Announcement Announcement Module
No announcement yet.
Validation and comparing two fields - via annotaion? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation and comparing two fields - via annotaion?

    I have an object that represents the form and having applied validation to the fields by means of annotations. I have two questions in this regards:
    - how to ensure value of a field matches that of another field, for example when ensuring the confirmation password matches the first
    - how to only apply the validation on a field based on the state of another field or session value.

    While I could do all of this within the controller or using a traditional validator, I want to see if it is possible via annotations.

  • #2
    You need to write a class level validator. Check out the Hibernate site on this subject, Hibernate validation. I have used this approach before. With the approach, your code looks tidy, but you need to write some extra code you may not understand it later. It is easier to use the straight forward Spring validation code structure instead.


    • #3