Java Reference
In-Depth Information
Figure 4.8: An error detected by a validation method
The Final Step: What to Do About Validation Errors?
When there are errors at the end of the validation process, the default
behavior is to send the user back where they came from instead of
executing the event handler. The list of errors is made available to the
view page.
We can gain control of what happens in the presence of validation errors
by having the action bean implement the ValidationErrorHandler interface,
which has one method:
public interface ValidationErrorHandler {
Resolution handleValidationErrors(ValidationErrors errors)
throws Exception;
}
This method is called after the validation process if at least one valida-
tion error occurred and the list of errors is passed as a parameter. In
the method, we can do pretty much anything, including the following:
• Change the list by adding, modifying, or deleting errors
• Change properties in the action bean
• Make calls to a DAO, and so on
We can also decide what happens next:
• If we return a Resolution , it is executed directly instead of returning
to the source page.
• If we return null and the list of errors is not empty, the user is
returned to the source page.
 
 
 
Search WWH ::




Custom Search