Dec 12th, 2010, 04:12 PM
Validate object fields that are not form fields with JSR-303 @Valid and annotations?
Hibernate's validator is my JSR-303 provider in my Spring MVC application. When I use @Valid, and then use the JSR-303 annotations on the form object fields, it validates just fine. However, there are some instances where I want to validate object fields that do not map one-to-one with jsp input fields. For example, I have a registration form with password and re-enter password input fields. The validation constraint should be @AssertTrue on a boolean object field that looks to see if password and re-enter password match. Hibernate's documentation shows that this is possible, but you have to invoke the validator manually, which defeats the purpose of my current approach with Spring annotations. Is there a way to do this in Spring without invoking the Hibernate validator?
Dec 12th, 2010, 09:49 PM
I just found this:
Which links to this:
Unless someone can provide some further clarification, it appears that when using @Valid, it is not possible to bind additional data (that did not come from an html form element) to the form object for validation. You would still have to create a custom validator and call it.
Tags for this Thread