net.sourceforge.stripes.validation
Interface ValidationErrorHandler


public interface ValidationErrorHandler

Interface that can be implemented by ActionBeans to be notified of ValidationErrors that occur during validation and binding. In the case where an ActionBean does not implement this interface, the errors are marshalled, the user is returned to the page from which they came and the ActionBean instance is discarded.

Implementing this interface gives ActionBeans the chance to modify what happens when the binding and/or validation phase(s) generate errors. The handleValidationErrors method is invoked after all validation has completed - i.e. after annotation based validation and any ValidationMethods that are applicable for the current request. Invocation only happens when one or more validation errors exist. Also, note that setContext() will always have been invoked prior to handleValidationErrors(ValidationErrors), allowing the bean access to the event name and other information.

When the handleValidationErrors(ValidationErrors) method is invoked, the ActionBean may do one or more of the following:

For example, if you want to override the validation service's results and continue execution, you might invoke errors.clear() to remove all the errors. Doing this makes it as though the errors had never been generated! Or perhaps for a specific ActionBean you'd like to redirect to a different error page instead of the page the user came from, in that case you can simply return a new ForwardResolution or RedirectResolution to change where the user will be sent.

Returning a Resolution from this method is stricly optional. If a Resolution is returned it will be executed instead of the error resolution. If null is returned (and one or more errors persist) then the error resolution will be executed as normal.

Author:
Tim Fennell

Method Summary
 Resolution handleValidationErrors(ValidationErrors errors)
          Allows the ActionBean to influence what happens when validation errors occur during validation and binding.
 

Method Detail

handleValidationErrors

Resolution handleValidationErrors(ValidationErrors errors)
                                  throws Exception
Allows the ActionBean to influence what happens when validation errors occur during validation and binding. See class level javadoc for full description of behaviour.

Parameters:
errors - the set of validation errors generated during validation and binding
Returns:
null, or a Resolution specifying what should happen next if non-standard behaviour is desired
Throws:
Exception - may throw any exception, but this will generally result in a ServletException being thrown on up the stack


? Copyright 2005-2006, Stripes Development Team.