The gender validation is not working. Even if no values are entered in the gender text field, the form is getting validated successfully without throwing any error.
Below is the Employee class:
@Size(min=2,max=10)
private String gender;
// Setters and Getters
Below is the Controller method:
@RequestMapping(value="done", method = RequestMethod.POST)
public String validateForm(@Valid Employee employee, BindingResult result, ModelMap m){
if(result.hasErrors()){
System.out.println("Validation Failed!!!");
return "main";
}else{
System.out.println("Validation Succeeded!!!");
return "done";
}
}
Below is the context file:
<context:annotation-config />
<context:component-scan
base-package="com.XXX" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
Below is the jsp file:
<tr>
<td>
Gender:
</td>
<td>
<form:input path="gender"/>
<form:errors path="gender" cssStyle="color: red;"/>
</td>
</tr>
I am not able to find out whats missing but its something silly. Please help.
import javax.validation.constraints.Size;