3 Replies Latest reply on Jul 17, 2012 10:29 AM by srinivas nandula

    GraphValidator and Validation Groups

    srinivas nandula Newbie

      My Environment JSF2 + Richfaces + Hibernate validator



      I have  a page with 2 buttons. when i click one button only one UI component needs to be validated. When i click the other, the entire page with cross field validations need to be validated. To accomodate that I provided cross field validation methods in my bean and provided the @AssertTrue annotation, so that the validatoin happens after the model has been updated.


      The problem is in specifiying the validaton groups to the rich validator. How do i accomplish this? I tried the f:validateBean and specified the validaton groups with it, but it is not working.


      I can provide the validation groups on the graph validator by providing an array of classes which are intialized on the managed bean. But i do not know how to dynamically change the group based on user click event.


      If i cannot do this, i don't know how i can use Hibernate validator.


      Thanks for any help.



        • 1. Re: GraphValidator and Validation Groups
          srinivas nandula Newbie

          Thought i would add an example.


          I have a problem i am unable to resolve and thought you could help as i see you have provided input into issues like this.


          My environment is JSF2 + RichFaces + Hibernate validator


          i have 2 buttons on a page. when i click one button, only one UI Component needs to be validated. when i click the other, it needs to validate the whole form and perform cross field validations.


          I believe the best way to do this is using validation groups. I created groups accordingly. I am able to test my bean outside of JSF for validations based on the groups and it all works fine.


          But i am not able to specify the groups to the rich graph validator properly. How do i change the validaton groups based on the button clicked?


          Please find code below as an example



          <rich:graphValidator value="#{caregiverStipendBean.currentItem}"


                                                      summary="Invalid values: ">

                              <h:panelGrid style="width:80%">


                                  <h:inputText  value="#{mybean.ssn}" />                       

                                  <h:commandButton value="Search SSN"

                                      action="#{caregiverStipendBean.searchCaregiver}" >                                          



                                  <h:inputText  value="#{mybean.password}" />                      


                                  <h:outputText>reenter password</h:outputText>

                                  <h:inputText  value="#{mybean.confirmationpassword}" />                      


          <h:commandButton value="Save"

                                      action="#{caregiverStipendBean.save}" >                                          





          As you can see , i have 2 buttons. The save button should validate the entire form and do cross field validation. But the search ssn should only validate the ssn field.


          To accomplish this, i created 2 validation groups. One for validating the SSN and the other for validating the remaining fields along with SSN.


          How do i change the validation groups based on click of a button? I just provided the example above for simplicity. My actual from is little more components than what i provided in this.


          Any help is greatly apprecieated.





          • 2. Re: GraphValidator and Validation Groups
            iabughosh Master

            hello nadula,

            i think you don't have problems with save button, your problem is with search button, you can edit your search button like this :

            <h:inputText id="ssnTxt"  value="#{mybean.ssn}" />

            <a4j:commandButton value="Search SSN"






            by executing only ssnTxt, only ssnTxt will be validated.



            • 3. Re: GraphValidator and Validation Groups
              srinivas nandula Newbie

              I tried what you suggested, but it does not work. I think if i was using the JSF Validators that might work. But i am using the graph validator which validates the entire form and i need to specify the validation groups.


              How do i specify different validation groups to the rich graph validator? i tried something like this.


              <rich:graphvalidator groups = {#param('GROUPS'} and with the action i was trying to pass a param GROUPS with the required validation group. But that does not work.


              I have to use the rich:graphvalidator because JSF2 does not work with hibernate cross field validations.


              Can you suggest something?