struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste Nizet <>
Subject prepare action for input after validation errors
Date Sun, 07 Sep 2008 14:12:45 GMT

I'm reading the documentation for Struts 2 (after lots of work on Struts 
1 and Beehive), and I wonder if an interceptor exists in order to 
prepare the action after the validation fails, and before going back to 
the input page. Imagine the following action class :

public class MyAction extends ActionSupport {
   public String displayForm() {
      return INPUT;

   private void prepareForInput() {
      // go to the database and get some data in order to display it in 
the input form page

   public String submitForm() {
      // this action is only called if validation succeeds
      // submits the form and returns a redirect result 
      return SUCCESS;

   public void validateSubmitForm() {
      // validation logic for the submitForm action
      // after this call, if there is an error, the workflow interceptor 
will return the INPUT result, but the necessary data won't be in the action
      // because the prepareForInput method hasn't been called

Is there an interceptor that would call my prepareForInput method?
I could call it in the validateSubmitForm method, but the validation 
logic would have a side effect, and I wouldn't be able to validate 
declaratively anymore.
I could call the prepareForInput method from the page, but the global 
exception handling wouldn't work (AFAIK) in the case an exception is 
thrown from this method.
I could use a Prepare interceptor, but the it would prepare regardless 
of the result of the validation.
The best way I see would be to use a subclass of the workflow 
interceptor (or add another interceptor after validation) that would 
automatically call a method named, for example, postValidationError or 
postValidationErrorSubmitForm before returning the INPUT result. Is 
there such a beast? How do you usually solve this problem?



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message