I'm trying to use the Validator framework for client-side validation of a multi-page form, but I can't get it work. At least not really ... Validation works fine for the very first page, but for any other page the wrong javascript-code is generated. No matter on which page I currently am, the source-code always contains the javascript-code for validating the field(s) from the very first page.
The main problem is that I don't really know where to increment/decrement the page counter. I tried to add a hidden field with the page number of the next page, so that I should at least be able to navigate forward, but that didn't work. Setting the page number in the Action didn't work either. Any ideas what I'm doing wrong? WizardLookupDispatchAction: --------------------------- public class WizardLookupDispatchAction extends LookupDispatchAction { private int page = 1; public WizardLookupDispatchAction() { keyMethodMap = new HashMap(); keyMethodMap.put("button.prev", "doPrevious"); keyMethodMap.put("button.next", "doNext"); keyMethodMap.put("button.finish", "doFinish"); } protected Map getKeyMethodMap() { return keyMethodMap; } public ActionForward doPrevious(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("WizardLookupDispatchAction.doPrevious()"); this.page -= 1; PropertyUtils.setSimpleProperty(form, "page", new Integer(page)); return mapping.findForward("previous"); } public ActionForward doNext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("WizardLookupDispatchAction.doNext()"); this.page += 1; PropertyUtils.setSimpleProperty(form, "page", new Integer(page)); return mapping.findForward("next"); } public ActionForward doFinish(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("WizardLookupDispatchAction.doFinish()"); return mapping.findForward("finish"); } } struts-config.xml: ------------------ <form-bean name="WizardForm" type=" org.apache.struts.validator.DynaValidatorForm"> <form-property name="username" type="java.lang.String" /> <form-property name="password" type="java.lang.String" /> <form-property name="ssn" type="java.lang.String" /> <form-property name="page" type="java.lang.Integer" initial="0" /> </form-bean> <!-- Wizard mappings --> <!-- Step 1 --> <action path="/step1" name="WizardForm" scope="session" type=" org.apache.struts.actions.ForwardAction" parameter="/step1.jsp" validate="false" /> <action path="/processStep1" name="WizardForm" scope="session" type="WizardLookupDispatchAction" parameter="methodToCall" validate="false"> <forward name="next" path="/step2.do" /> </action> <!-- Step 2 --> <action path="/step2" name="WizardForm" scope="session" type=" org.apache.struts.actions.ForwardAction" parameter="/step2.jsp" validate="false" /> <action path="/processStep2" name="WizardForm" scope="session" type="WizardLookupDispatchAction" parameter="methodToCall" validate="false"> <forward name="previous" path="/step1.do" /> <forward name="next" path="/step3.do" /> </action> <!-- Step 3 --> <action path="/step3" name="WizardForm" scope="session" type=" org.apache.struts.actions.ForwardAction" parameter="/step3.jsp" validate="false" /> <action path="/processStep3" name="WizardForm" scope="session" type="WizardLookupDispatchAction" parameter="methodToCall" validate="false"> <forward name="previous" path="/step2.do" /> <forward name="finish" path="/wizard_done.jsp" /> </action> validation.xml -------------- <form name="WizardForm"> <field property="username" page="0" depends="required"> <arg0 key="prompt.username" /> </field> <field property="password" page="1" depends="required"> <arg0 key="prompt.password" /> </field> <field property="ssn" page="2" depends="required"> <arg0 key="prompt.ssn" /> </field> </form> stepX.jsp --------- <html:javascript formName="WizardForm" /> <html:form action="/processStepX.do" method="post" onsubmit="return validateWizardForm(this);"> <table class="form"> <tr> <td colspan="2"><html:errors /></td> </tr> <tr> <th>propertyX</th> <td><html:text property="propertyX" /></td> </tr> <tr> <td><html:submit property="methodToCall"><bean:message key='button.prev' /></html:submit></td> <td><html:submit property="methodToCall"><bean:message key='button.next' /></html:submit></td> </tr> </table> </html:form>