This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes declarative validation of wizard pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "declarative validation of wizard pages" Watch "declarative validation of wizard pages" New topic
Author

declarative validation of wizard pages

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hello,

i have a kind of wizard: a set of pages which are all filled from the same form (a ValidatorForm) and all processed by the same action (which - if necessary - forwards the request to the appropriate special action)

i want to use declarative validation for that.

suppose i have field A on page 1, field B on page 2, let both be required.

when validation fails, the processor would normaly forward the request to the (single) page defined with the input attribute.

what i obviously want is
- if field A is missing, forward to page 1
- if field B is missing, forward to page 2

is there any way that i can achieve this declaratively?

thanks a lot,
jan
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
As I see it, the best way to achieve this is to create a separate action mapping for each page. Even if you are using the same Action class for every page, you can still have a separate Action mapping. example:

<action name="wizardForm" path="/Page1" type="com.mycompany.WizardAction" input="/page1.jsp" />
<action name="wizardForm" path="/Page2" type="com.mycompany.WizardAction" input="/page2.jsp"/>
<action name="wizardForm" path="/Page3" type="com.mycompany.WizardAction" input="/page3.jsp"/>

You would then have your form bean extend ValidatorActionForm instead of ValidatorForm. In the validation.xml file, you would specify the action path as the name attribute of the form tag instead of the ActionForm name. Then include only the fields processed by that action path (page).

Since there is a separate input page for each action mapping, the Validation Framework will return to the correct page if there's an error.


Merrill
Consultant, Sima Solutions
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
a perfect solution. thanks a alot, merrill!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: declarative validation of wizard pages
 
Similar Threads
Redisplaying a page after validation due to validation errors?
Handling data carry between different pages - Design handliing.
DispatchAction question
Struts2 wizard with scoped model driven
Form Validation