I couldn't get this to work after following every instruction in the spring modules online documentation. When I click the next button on my registration page (with some required fields left empty), I simply see the next page in the order. No validation is happening. Can someone help?
Here is my code and configuration.
Controller code:
===============
protected void validatePage(Object command, Errors errors, int page) {
User user = (User)command;
Validator validator = (DefaultBeanValidator)getValidator();
if(page == 0){
validator.validate(user, errors);
}
}
registerForm.jsp:
================
<form:form action="register.htm" method="post" commandName="user">
<table>
<tr>
<td>User Name*</td>
<td>
<form:input path="userName" />
<form:errors path="userName" cssClass="error"/>
</td>
</tr>
<tr>
<td>Password*</td>
<td>
<form
assword path="password" />
<form:errors path="password" cssClass="error"/>
</td>
</tr>
<tr>
<td>Re-enter password*</td>
<td>
<form
assword path="confirmPassword" />
<form:errors path="confirmPassword" cssClass="error"/>
</td>
</tr>
<tr>
<td>First Name*</td>
<td>
<form:input path="firstName" />
<form:errors path="firstName" cssClass="error"/>
</td>
</tr>
<tr>
<td>Middle Initial</td>
<td><form:input path="middleInitial" /></td>
</tr>
<tr>
<td>Last Name*</td>
<td>
<form:input path="lastName" />
<form:errors path="lastName" cssClass="error"/>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="_target1" value="Next" />
<input type="submit" name="_cancel" value="Cancel" />
</td>
</tr>
</table>
</form:form>
Spring config:
=============
<bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory">
<property name="validationConfigLocations">
<list>
<value>WEB-INF/validator-rules.xml</value>
<value>WEB-INF/validation.xml</value>
</list>
</property>
</bean>
<bean id="beanValidator" class="org.springmodules.validation.commons.DefaultBeanValidator">
<property name="validatorFactory" ref="validatorFactory" />
</bean>
<bean name="/register.htm" class="com.estore.controller.RegistrationController">
<property name="pages">
<list>
<value>registerForm</value>
<value>addressInfo</value>
<value>paymentInfo</value>
<value>registerSuccess</value>
<value>redirect:home.htm</value>
</list>
</property>
<property name="userService" ref="userService" />
<property name="lookupService" ref="lookupService" />
<property name="validator" ref="beanValidator" />
<property name="commandName" value="user"/>
<property name="commandClass" value="com.estore.command.User"/>
</bean>
validaton.xml
=============
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD
Commons Validator Rules Configuration 1.1//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
<form-validation>
<formset>
<form name="user">
<field property="userName" depends="required">
<arg0 key="required.username" />
</field>
<field property="password" depends="required">
<arg0 key="required.password" />
</field>
<field property="confirmPassword" depends="required">
<arg0 key="required.confirmpassword" />
</field>
<field property="firstName" depends="required">
<arg0 key="required.firstname" />
</field>
<field property="lastName" depends="required">
<arg0 key="required.lastname" />
</field>
</form>
</formset>
</form-validation>
validator-rules.xml
===================
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
<form-validation>
<global>
<validator name="required"
classname="org.springframework.validation.commons.FieldChecks"
method="validateRequired"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.springframework.validation.Errors"
msg="errors.required">
<javascript><![CDATA[....
]]>
</javascript>
</validator>
<validator name="requiredif"
classname="org.springframework.validation.commons.FieldChecks"
method="validateRequiredIf"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.springframework.validation.Errors,
org.apache.commons.validator.Validator"
msg="errors.required">
</validator>
</global>
</form-validation>