Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Bean Validator Not Called

 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This class level bean validation call is not being called.






It is being called like this:



The only way I can get it to be called is when I place it on a field. Any ideas what is going on?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18012
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you're attempting to attach a Validator to a container element. That doesn't work. Validators can only be applied to individual control elements.

I wrote one of these sorts of validators. It was for the traditional "enter-the-password-twice" control pair. What I had to do was attach it to one of the password controls, which then supplied its value to the validator. For the matching value in the other control, I (the validator) had to retrieve that control from the view tree, get its value, compare to the value passed in and then throw the ValidationException if they didn't match.
 
Andy Holm
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What? I don't think we are on the same page, Tim.

This is a bean validation validator that uses the Hibernate bean validation annotation APIs. It has no access to the view tree (nor should it). There are examples of how this can be attached to a class so it shouldn't be a problem (http://stackoverflow.com/questions/1972933/cross-field-validation-with-hibernate-validator-jsr-303). Unfortunately, I can't get it to work anywhere other than on a field or method. It isn't called on a constructor for me either.

If it helps, I am using Apache Tomcat 6 and have downloaded hibernate-validator-4.1.0.jar to patch it to support annotations in EE 6. More information on what I did is shown here under Bean Validation (http://weblogs.java.net/blog/cayhorstmann/archive/2009/12/29/jsf-20-and-tomcat).

If this needs to be moved to a different part of the forum than the JSF section, feel free to move it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic