3 Replies Latest reply on Jul 7, 2010 9:05 AM by riotrellik

    Validate check boxes?

    riotrellik

      I have been given a project that uses RichFaces... I have never used it, and don't know much about AJAX or JS.

       

      What I am doing, or trying to do is have two checkboxes, I need at least one of them to be chosen, and I need it to not submit if at least one or both is not checked.

       

      I have figured out the very easy to use form field validation, but have found no documentation or example of a multiple check box validation.

       

      Any help would be greatly appriciated.

       

      Thanks you.

       

      example code:

       

       

      <h:selectBooleanCheckbox title="participantAccess" value="#{dcSite.userParticipantAccess}" />PARTICIPANT
      <f:verbatim>
      <br />
      </f:verbatim>
      <h:selectBooleanCheckbox title="sponsorAccess" value="#{dcSite.userSponsorAccess}" />SPONSOR
      
      
      

       

      if this were ActionScript I would right a function that would see if one or both had been checked, but I am not sure how to go about this in this.

        • 1. Re: Validate check boxes?
          riotrellik

          So been messing around, searching like crazy,

           

          And I have an idea, what if I add a function to the bean that has an if / else statement that would logically run through and make sure that at least one of the two checkboxes was checked?

           

           

           

          public void validateSiteCreation(userParticipantAccess,userSponsorAccess) {
               if ( userParticipantAccess.equals(null) && ( userSponsorAccess.equals(null) {
                    //reject submission
               } else if ( userParticipantAccess.equals(!null) && ( userSponsorAccess.equals(null) {
                    //send submission
               } else if ( userParticipantAccess.equals(null) && ( userSponsorAccess.equals(!null) { 
                    //send submission
               }
          };
          
          
          • 2. Re: Validate check boxes?
            nbelaevski

            Hi Pete,

             

            Take a look at rich:graphValidator. Another options are discussed in this thread: http://community.jboss.org/thread/139135?tstart=0 or search Google for examples of cross-field AJAX validtion.

            • 3. Re: Validate check boxes?
              riotrellik

              Thanks for the direction Nick, still reads alot like greek, but working on it!