permaculture playing cards*
The moose likes JSF and the fly likes Custom Bean Validator Not Called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Custom Bean Validator Not Called" Watch "Custom Bean Validator Not Called" New topic
Author

Custom Bean Validator Not Called

Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
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

Joined: Jun 25, 2001
Posts: 16160
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Custom Bean Validator Not Called