aspose file tools*
The moose likes Struts and the fly likes How to use Formbean's validate method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use Formbean Watch "How to use Formbean New topic
Author

How to use Formbean's validate method?

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
Hi,

I have an DispatchAction subclass which can forward to multiple JSP's based on a prameter.

My action entries in the sturts config.xml looks like


In my Action form i have a validate method which validate the form details (For the action class mentioned above there is a single form bean OrderForm). My requriement is

1. If the user has validation errors in personalDetails.jsp, he should be redirected again to personalDetails.jsp
2. if the user has validation errors in cardDetails.jsp he should be redirected to cardDetails.jsp

and so on.

My question is

if i use the formbean's validate() method to acheive the above quoted requirement, it redirects always to the personalDetails.jsp irrespective of the page which failed the validation. (even if cardDetails.jsp validation fails it redirects to personalDetails.jsp) How to overcome this and redirect to the specified page?

Thanks,
Xavier.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd recommend you create multiple action mappings all pointing to the same Action class, but with different input attributes. This way you don't have to change the code in your Action class or validate method at all, but Struts will forward to the right JSP if there's an error. All you have to change is the action attribute of the <html:form> tag for each page.

Example:


Merrill
Consultant, Sima Solutions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use Formbean's validate method?
 
Similar Threads
how to show errors on the same page?
Struts Validation with ArrayLiist of beans
Redisplaying a page after validation due to validation errors?
Struts login using JAAS and login-config
Behaviour on failure of validate in form bean