Java Reference
In-Depth Information
there are previous validation errors. The value must be a
ValidationState
,
which is an
enum
with these possible values:
•
ALWAYS
: Executes the validation method even if there are previous
validation errors
•
NO_ERRORS
: Executes the validation method only if there are no
previous validation errors
•
DEFAULT
: Uses the default behavior of the application
For example, this validation method will be executed regardless of pre-
vious errors:
@ValidationMethod(when=ValidationState.ALWAYS)
public void
validateSomething(ValidationErrors errors) {
// ...
}
The default value of
when=
is, not surprisingly,
ValidationState.DEFAULT
.
This means “use the application's default,” and that default is
Validation-
State.NO_ERRORS
. You can change the “application default” to
Validation-
State.ALWAYS
by adding an initialization parameter to the Stripes filter
in
web.xml
:
<filter>
<filter-name>
StripesFilter
</filter-name>
<filter-class>
net.sourceforge.stripes.controller.StripesFilter
</filter-class>
<!-- ... -->
<init-param>
<param-name>
Validation.InvokeValidateWhenErrorsExist
</param-name>
<param-value>
true
</param-value>
</init-param>
</filter>
With this configuration, validation methods will always be executed by
default. To execute a validation method only if there are no previous
errors, you'd have to explicitly add
when=ValidationState.NO_ERRORS
to
@ValidationMethod
.
Whether you are changing the default or using the
when=
attribute,
when you execute a validation method even if previous errors have
occurred, the fields could contain invalid values or even be
null
. Keep
that in mind when writing the code for a validation method that will
always be executed.
Search WWH ::
Custom Search