Meaningless Drivel is fun!
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to use Formbean Watch "How to use Formbean New topic

How to use Formbean's validate method?

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109

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?

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.


Consultant, Sima Solutions
I agree. Here's the link:
subject: How to use Formbean's validate method?
It's not a secret anymore!