Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Formbean's validate method?

 
Ajay Xavier
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic