3 Replies Latest reply on Aug 25, 2010 2:42 AM by Ilya Shaikovsky

    BeanValidation fired each time an ajax request

    Kto ToTaki Newbie

      Hi There is maybe something I missed, but I thought that  should be controlled  by an submit action on a form. In my case, the validation is fired on an every ajax request,  long before a user has completed a form.  Take a look on this example :


           <h:form >
                      <rich:tabPanel switchType="ajax" id="orderlisteTab"  >
                          <rich:tab label="#{txt.tab_search}" id="tab1" >
                                              <rich:message for="fodselsnr" showSummary="true" showDetail="false" />
                                                  <label for="fodselsnr">#{txt.lblBirthnumberWithExplanation}</label>
                                                  <h:inputText id="fodselsnr" value="#{pointing to a field in a bean with JSR 303 validation...}" >
                                                      <rich:beanValidator />
                                        <div >
                                          <a4j:commandButton actionListener="#{...}"  />
                          <rich:tab label="#{txt.tab_search_advanced}" id="tab2" >



      BeanValidation concern only one value which is pointing to a bean with a field with validation like this :





      When I try to change tab and go to tab2, with empty "fodselsnr", validation executes which give me a error and stop me to perform this action.

      What I want, is to execute a validation when   is executed, not before.

      How to get this behavior ?

        • 1. Re: BeanValidation fired each time an ajax request
          Nick Belaevski Master

          Hi Mirek,


          You can set immediate="true" for tab panel, so that it will switch with any validation result, however this will block updating the property with new value. Better alternative is switching to 'client' mode.

          • 2. Re: BeanValidation fired each time an ajax request
            Kto ToTaki Newbie

            Hi Nick,

            You have right, in this case, but normally you need to interact with bean (read switchType !="client") to perform some action when a user change tabs, but it is not what is important in this case !


            What I want is to get control on validation on my own and trigger validation when its necessary.


            I tried with  around inputText to limit updates to region only, tried  but steel the same behavior is recorded.


            I had to "manually" perform validation, removing tags from the page and placing code like this on actionListener code in the bean for submit button :


            private Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

            public void sjekkFodselsnrOgSok(){

                 Set> constraintViolations = validator.validate(fnrSjekk);

                 int antallValideringsFeil = constraintViolations.size();

                 if(antallValideringsFeil > 0){...}

            ...           }


            Is there any way to use <rich:???Validation> tags and control validation on form submitting ?

            • 3. Re: BeanValidation fired each time an ajax request
              Ilya Shaikovsky Master

              if you want to switch tabs via ajax without validation and perform validations/model updates only on clicking links/buttons - just remove form around the tabPanel and insert separate forms to every tabs.