Java Mailing List Archive

http://www.gg3721.com/

Home » Struts Users Mailing List »

prepare action for input after validation errors

Jean-Baptiste Nizet

2008-09-07

Replies: Find Java Web Hosting

Author LoginPost Reply
Hello.

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() {
   prepareForInput();
   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
(redirect-after-post)
   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?

Thanks.

JB.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 gg3721.com - Jax Systems, LLC, U.S.A.