Struts: where to prepare page data if validation fails
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Friday, November 19, 2004 01:54 PM

Hi, I have been having trouble understanding Struts Validation architecture in one aspect. When form validation fails, then the immediate forward to input page is executed bypassing the execute() method of an action. This works fine if the page displays only the form contents and does not need any additional data preparation, or if all the data is already in the session scope. It is not the case in all the applications I've developed. A standard example is a data list with some filter form fields. The list data is fetched from the DB during action processing and put in the request scope for rendering in jsp. If filter fields validation fails, the list will not be prepared as shown on the previous page. :(    More>>

Hi,


I have been having trouble understanding Struts Validation architecture in one aspect. When form validation fails, then the immediate forward to input page is executed bypassing the execute() method of an action. This works fine if the page displays only the form contents and does not need any additional data preparation, or if all the data is already in the session scope. It is not the case in all the applications I've developed.


A standard example is a data list with some filter form fields. The list data is fetched from the DB during action processing and put in the request scope for rendering in jsp. If filter fields validation fails, the list will not be prepared as shown on the previous page. :(


I am wondering if the Struts architects had any better idea than setting validate="false" in action definition in struts-config and calling form.validate() explicitely in the action execute(..) method.


Thanks.    <<Less

Re: Struts: where to prepare page data if validation fails

Posted By:   Jerome_Iffrig  
Posted On:   Sunday, November 21, 2004 04:32 AM

Like anything in Servlet stuff, there are different ways to do this.

In the case you described, I would do my initialisations in the reset() method.

This method is called before the JSP is displayed (or re-displayed).


Alternatively, if you like doing things in an execute() method, put your initialisation code in an new action.execute() which purpose is to put things in the request scope.


Just make sure that you use forward rather than redirect in your struts mapping (when you redirect, elements in the request scope are wipped out).


Not sure my explanation is clear as it is difficult to explain in a text, but I hope it gives you a kick.

Jerome

About | Sitemap | Contact