Java Reference
In-Depth Information
For example:
new SimpleError("Invalid input");
new SimpleError("For field {0}, the value {1} is not valid");
new SimpleError("{1} is not valid because {2}", someText);
Once you've created a validation error, you can associate it to a spe-
cific field using the field name such as "age" or "contact.firstName", or
you can make it a global error. Add the error to ValidationErrors with the
appropriate method:
void add(String field, ValidationError error)
void addGlobalError(ValidationError error)
After adding errors to the list, you can display them in the JSP with the
<s:errors/> tag just like built-in validation error messages. As we'll see
in Chapter 6 , Customizing Stripes Messages, on page 121 , you can also
display errors next to their associated fields and display global errors
at the top.
Restricting Validation Methods to Specific Event Handlers
@ValidationMethod accepts the on= attribute to restrict the validation to
specific event handlers:
// on the "save" and "update" event handlers
@ValidationMethod(on={"save", "update"})
// on every event handler except "save"
@ValidationMethod(on="!save")
Just like the on= attribute of @Validate , this lets you control the event
handlers for which your validation methods are executed.
Continue or Stop Validation When There Are Previous Errors?
Stripes invokes validation methods after all @Validate s have been pro-
cessed and the inputs have been bound to the action bean's proper-
ties. By default, Stripes does not invoke a validation method if errors
occurred during the execution of previous validations, including @Vali-
date s as well as @ValidationMethod s of higher priority. The idea is that
you know every previous validation has passed when executing a given
validation method.
You can control this behavior with the when= attribute of @Validation-
Method . This indicates whether to execute the validation method when
 
 
 
Search WWH ::




Custom Search