3 Replies Latest reply on Apr 3, 2009 6:31 AM by ilya_shaikovsky

    Ajax Validator: Field Highlighting on validation error

      Hi Everyone,
      I would like to know the possibility to highlight a field,
      if a validation error occur for that field through ajaxValidator or beanValidator.


      Any help would be highly appreciated.

      Thanks

        • 1. Re: Ajax Validator: Field Highlighting on validation error
          ilya_shaikovsky

          you could add ajaxListener (it called before render responce so even if validation failed) which will check if the messages exist and which components rised them and add proper styleClasses.

          • 2. Re: Ajax Validator: Field Highlighting on validation error

             

            "ilya_shaikovsky" wrote:
            you could add ajaxListener (it called before render responce so even if validation failed) which will check if the messages exist and which components rised them and add proper styleClasses.


            I tried to add a ajaxListener like this
            <s:div id="myinputdiv">
             <h:inputText id="input1" value="#{testBean.someInputText}" >
             <f:validateLength minimum="3" maximum="12"/>
             <rich:ajaxValidator ajaxListener="#{testBean.listenAjaxRequest}"
             event="onblur" reRender="myinputdiv" />
             </h:inputText>
            </s:div>
            


            then in managed bean

            public void listenAjaxRequest(AjaxEvent ajaxEvent) {
             HtmlBeanValidator beanValidator = (HtmlBeanValidator) ajaxEvent.getSource();
             HtmlInputText htmlInputText = (HtmlInputText) beanValidator.getParent();
             if (htmlInputText.isValid()) {
             htmlInputText.setStyleClass(null);
             } else {
             htmlInputText.setStyleClass("ierror");
             }
             }
            


            I could see the listener method is called as expected but somehow reRender is not working.
            That means validation error message was shown but still input field remains without any style change.

            Please help me to fix this.

            • 3. Re: Ajax Validator: Field Highlighting on validation error
              ilya_shaikovsky

              need to check responce returned.

              b.t.w. sorry.. there is much more easier way.. read about seam s:decorate.