Announcement Announcement Module
Collapse
No announcement yet.
Validate object fields that are not form fields with JSR-303 @Valid and annotations? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #2
    I just found this:

    http://forum.springsource.org/showthread.php?t=84913

    Which links to this:

    https://jira.springframework.org/browse/SPR-6437

    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.

    Comment

    Working...
    X