Reputation: 419
I have a validation.xml
file to check if the fields of the form are empty and that kind of simple validation. I also have a validate()
method (extended from ActionSupport
) to check more complicated things.
But, when I send the form, it checks the method before the XML file, so if the fields are empty a NullPointerException
appears. At least, that's what I think is happening.
So, my question is, is there a way to change the order of the validation, so the XML is checked before the method?
EDIT:
I had the idea of checking if the String
is not null
in the validate()
method, so I can avoid the problem, but I don't think that's the wisest thing to do.
Upvotes: 2
Views: 228
Reputation: 1
The order is always the same, which is hardcoded order.
The process of validation is performed by the ValidationInterceptor
class (at least version 2.3.8).
This interceptor runs the action through the standard validation framework, which in turn checks the action against any validation rules (found in files such as
ActionClass-validation.xml
) and adds field-level and action-level error messages (provided that the action implementsValidationAware
). This interceptor is often one of the last (or second to last) interceptors applied in a stack, as it assumes that all values have already been set on the action.This interceptor does nothing if the name of the method being invoked is specified in the
excludeMethods
parameter.excludeMethods
accepts a comma-delimited list of method names. For example, requests tofoo!input.action
andfoo!back.action
will be skipped by this interceptor if you set theexcludeMethods
parameter to"input, back"
.The workflow of the action request does not change due to this interceptor. Rather, this interceptor is often used in conjunction with the
workflow
interceptor.NOTE: As this method extends off
MethodFilterInterceptor
, it is capable of deciding if it is applicable only to selective methods in the action class. SeeMethodFilterInterceptor
for more info.
First, it checks if the declarative validation is enabled and do it, then it checks if programmatic validation is enabled and do it.
You can turn on/off each type of validation via the interceptor parameters.
Interceptor parameters:
alwaysInvokeValidate
- Defaults totrue
. Iftrue
validate()
method will always be invoked, otherwise it will not.programmatic
- Defaults totrue
. Iftrue
and the action isValidateable
callvalidate()
, and any method that starts with"validate"
.declarative
- Defaults totrue
. Perform validation based on XML or annotations.
Upvotes: 1
Reputation: 160181
The interceptor does check XML first, but IIRC doesn't stop validation if it find errors. I believe I have a patch for this, controlled with a flag.
I've solved this before by checking for errors in the validate
method and not proceeding if errors existed.
Upvotes: 3