This should help you 
http://struts.apache.org/2.0.11.1/docs/how-do-we-repopulate-controls-when-validation-fails.html
FAQ:How do we repopulate controls when validation fails .
You can use the Preparable interface to load the data from the database.
Validation does not (by default config) run on result of "input".



Brian Hawkins-3 wrote:
> 
> I've run into a situation that I would like to get others opinions on.
> 
> The problem is with handling a form.  Here is the scenario: I have a form
> called form.jsp, this form needs data from the database so it has an
> associated FormAction.java class.  The struts.xml file looks like this:
> 
> <action name="myForm" class="FormAction">
> <result>/form.jsp</result>
> </action>
> 
> The form then posts the data to another action called postForm and the
> struts.xml looks like this:
> 
> <action name="postForm" class="PostFormAction">
> <result>...</result>
> </action>
> 
> Now for the issues.  The first issue is field validation.  I can't just
> add
> an input result that points to /form.jsp because the form needs the data
> out
> of FormAction.  If I redirect to myForm I loose the field validation and
> the
> same goes for chaining (I know I can hack out the errors from the stack
> but
> that is ugly).  Using the session to save error info on is also ugly.
> 
> My preference is to use just one action class and have two methods.  I
> would
> use execute() to get the data to view the form and postData() for posting
> the data.  This way if postData found a field errors it could call execute
> and then return an input status.  This solution still has problems in
> terms
> of interceptor validators.  The validator needs to check for required
> fields
> only when the postData() method is called and not when execute is called
> and
> if there is an error when calling postData() it needs to call execute
> before
> returning an input status.  I would like to make a validator that is smart
> enough to know when to validate fields and when not to based on the method
> being called but I cannot find a way to get what method on the action is
> being called.
> 
> Is there a best practices on how to handle form data in an elegant manner?
> Is there a way to know what method is being called?
> So many questions and so few answers :(
> 
> thanks
> Brian
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Handling-form-data-tp16968494p16982984.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to