Here is an issue I have been stuck into. Actually, I implemented all required features in order to get couple of my field validated, however I still get that 400 error. I even compared what I have made with examples from Spring 3 for Professionals (taking their sourcecode); their examples work perfectly, and failed to find difference... :((( - maybe it is due to lack of attention again.
So, here is couple of fields properly annoted to be validated:
@NotEmpty(message="{validation.firstname.NotEmpty.message}")
@Size(min=3, max=60, message="{validation.firstname.Size.message}")
@Column(name = "FirstName")
public String getFirstName() {
return firstName;
}
@NotEmpty(message="{validation.lastname.NotEmpty.message}")
@Size(min=1, max=40, message="{validation.lastname.Size.message}")
@Column(name = "LastName")
public String getLastName() {
return lastName;
}
Their messages within messages.properties:
validation.firstname.NotEmpty.message=First name is required
validation.lastname.NotEmpty.message=Last name is required
validation.firstname.Size.message=First name must be between {min} and {max}
validation.lastname.Size.message=Last name must be between {min} and {max}
And yes, messages.properties is reachable, since I successfully get amother message related to success saving.
Here are related parts of methods within controller:
public String update(@Valid Employee employee,...
public String create(@Valid Employee employee,...
i.e. I put required @Valid annotation there.
Then part of my servlet-context.xml:
<annotation-driven validator="validator"/>
<beans:bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<beans:property name="validationMessageSource" ref="messageSource"/>
</beans:bean>
Here is related part of my edit.jspx
<form:label path="firstName"> ${labelEmployeeFirstName}* </form:label>
<form:input path="firstName" />
<div> <form:errors path="firstName" cssClass="error" /> </div>
<p/>
<form:label path="lastName">${labelEmployeeLastName}* </form:label>
<form:input path="lastName" />
<div> <form:errors path="lastName" cssClass="error" /> </div>
I don't know whether something else required to put here to clarify more...