1 Reply Latest reply on Feb 24, 2014 8:52 AM by ppitonak

    Richfaces 4.3.4: graphValidator Issue

    ripper9100

      Maybe I'm misunderstanding the functionality of this component but I expect that all values in my Bean will be validated but this is not happening. Here is some sample code illustrating the behavior I'm seeing:

       

      <h:form id="myForm">
        <rich:graphValidator value="#{testBean}" id="gv">
        <h:panelGrid columns="3">     
             <h:inputText value="#{testBean.str}"></h:inputText>    
             <h:inputText value="#{testBean.date1}" styleClass="datepicker"></h:inputText>
             <h:inputText value="#{testBean.date2}" styleClass="datepicker"></h:inputText>
        </h:panelGrid>
        <a4j:commandButton value="Submit" action="#{testBean.doAction}"/>
        </rich:graphValidator>
        </h:form>
      


      @ManagedBean
      @ViewScoped
      public class TestBean implements Cloneable, Serializable{
        private static final long serialVersionUID = 1952428504080910113L;
      
      
        private String str="";
      
        @Pattern(regexp="(^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$)?", message="Invalid date")
        private String date1;
      
        @Pattern(regexp="(^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d$)?", message="Invalid date")
        private String date2;
      
      
        @AssertTrue(message = "Invalid value")
        public boolean isStrValid() {
        return str.length() == 9 || str.isEmpty();
        }
      
      
      
      
      


      Assuming I enter invalid text in all 3 of the fields I've defined above I would expect to see 3 error messages, 2 for "Invalid date" and 1 for "Invalid value". This is not happening, instead I am seeing 2 "Invalid date" error messages. The only way I can get the "Invalid value" error message to show is by either leaving the 2 date fields blank or by entering valid values in the 2 date fields. If I enter an invalid value in either date field the "Invalid value" message will not show.


      Does anyone know why this happens?

        • 1. Re: Richfaces 4.3.4: graphValidator Issue
          ppitonak

          Hi,

           

          this happens by design. You shouldn't use r:graphValidator for common field validations. It was designed to allow you to do cross-field validation, e.g. you use @Pattern for validating that both date1 and date2 are dates in specified format and you use graphValidator to validate that date1 is later than date2.

           

          The easiest way to implement your use-case is to use @Pattern on your "str" field like this:

           

          @Pattern(regexp = "^$|.{9}")

          private String str = "";

           

          Regards,

          Pavol

           

          P.S. consider upgrading to RichFaces 4.3.5.Final