7 Replies Latest reply on Jan 22, 2010 4:11 PM by jpleed3

    Bean Validation in RF 3.3.3


      Is Bean Validation supposed to work out of the box in RichFaces 3.3.3? I have the constraint annotations placed on my JPA entities, but there aren't any Faces messages popping up for invalid input. However, when I try to commit changes JPA is reporting a ConstraintValidationException, so it looks like everything is working correctly except for JSF calling the bean validator during the appropriate phase.


      By the way, I'm using RF 3.3.3 BETA1 with Facelets 1.1.15 on Glassfish v3.

        • 1. Re: Bean Validation

          If I add Ctrl-V... Ctrl-V... Right-click... WTF, the new forum doesn't paste?


          Anyway, if I add <f:validator validatorId="javax.faces.Bean" /> to an input field, then bean validation will validate that field as expected. According to the JSF 2 spec section 2.5.7, JSF is supposed to pretty much do that for every UIInput.


          So I figured maybe I could add this:








          No luck there.

          • 2. Re: Bean Validation
            import javax.validation.constraints.Size;
             * Created by JBoss Tools
            public class Person {
                @Size(min = 2, max = 3)
                private String name;
                 public Person() {
                 public String getName() {
                      return name;
                 public void setName(String name) {
                      this.name = name;


                      <h:inputText value="#{person.name}">
                           <rich:beanValidator />
                      <h:commandButton value="Submit"/>
                      <a4j:commandButton value="Ajax Submit"/>

            both buttons causes messages to appear for me. I've used for test next env:

            • hibernate-validator-4.0.2.GA, 
            • RichFaces 3.3.3 - snapshot
            • JSF 2.0.1
            • tomcat 6
            • 3. Re: Bean Validation

              I'm running on Glassfish v3, so everything I need should be in the classpath, aside from Facelets 1.1.15 and RF 3.3.3.


              As long as a JSR-303 implementation is available, JSF 2 should automatically add the validator to every UIInput, unless the context-param javax.faces.validator.DISABLE_DEFAULT_BEAN_VALIDATOR is set to true. See JSF 2.0 spcc, section 2.5.7.


              So - at least from my understanding - it shouldn't be necessary to add <rich:beanValidator /> in JSF 2. I mean, I can understand why we can't use JSF 2 tags like f:ajax with RichFaces 3.3.3 - they simply don't exist in Facelets 1.1.15. But this shouldn't have anything to with the PDL, should it?

              • 4. Re: Bean Validation
                thanks for this update. I will continue investigation.
                • 5. Re: Bean Validation

                  Can't find precise place in JSF 2 specification but it seems for me that validators not instantiated by default if running in jsf 1.2 compatibility mode. I tried to create simple JSF 2 project from scratch and validators worked as you told till I added Facelets 1.1.15 and turned default VDL viewHandler off. Then I tried different definitions but default validators no more working without to be explicitly defined.


                  Thanks! I will add this to compatilibity limitations wiki document.

                  • 6. Re: Bean Validation
                    I don't think javax.faces.VALIDATE_EMPTY_FIELDS works either. I've gotten BV to work without the rich:beanValidator tag by using a phase listener that adds BeanValidator to all UIInputs, but I still have to put required=true on the inputs.
                    • 7. Re: Bean Validation
                      I filed an issue with Mojarra; maybe this limitation will get some attention: https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1518