3 Replies Latest reply on Apr 16, 2010 4:07 PM by ssilvert

    How to test input & rich:ajaxValidator event="onblur" & rich:message

    jadtn

      Hi,

      There is someone who has already tested the presence of an error message with rich:ajaxvalidator for event="onblur"?

      I think client.setValue(inputId, value); do nothing on event "onblur"....

      If someone has an example, it would be nice.

       

      {code:xml}

      <h:inputText id="nupseudo" value="#{ctrlCreateUser.newUser.userId}"  size="16" maxlength="#{ctrlCreateUser.maxPseudoLength}"  required="true">
                   <f:validator validatorId="pseudoValidator" />
                  <rich:ajaxValidator event="onblur" />
        </h:inputText>
      <rich:message for="nupseudo" />

      {code:xml}

       

      Thanks

      Adrien

        • 1. Re: How to test input & rich:ajaxValidator event="onblur" & rich:message
          ssilvert

          Hi Adrien,

           

          I've never tried this before.  You might need to Using the HtmlUnit API with JSFUnit and also post on the HtmlUnit mailing list to ask exactly how/when onblur gets fired.

           

          Stan

          1 of 1 people found this helpful
          • 2. Re: How to test input & rich:ajaxValidator event="onblur" & rich:message
            jadtn

            To test ajaxValidator it is need to use a HtmlElement to change the component focus

            Here a sample code

             

             

            //set focus on the input to modify

            setFocusOn("nupseudo");
            //update the input
            client.setValue("nupseudo", newUser);
            //change the focus
            setFocusOn("anotherInputForExample");

            //check the error message

            checkContainsMsg("nupseudo", "excpected error message")

             

             

            public void setFocusOn(String componentId){
                    HtmlPage p = (HtmlPage) client.getContentPage();//JSFClientSession
                    HtmlElement m = p.getHtmlElementById(componentId);       
                    p.setFocusedElement(m);//change the focus to declenche ajaxvalidar
                }

            public    void checkContainsMsg(String cptid, String msg) {
                    Iterator<FacesMessage> msgs = FacesContext.getCurrentInstance().getMessages(cptid);
                    String allmsg="";
                    while (msgs.hasNext()) {
                        FacesMessage m = msgs.next();   
                        allmsg= allmsg+ "[sum='"+m.getSummary()+"',Det='"+m.getDetail()+"',SEV="+m.getSeverity()+"]";
                        if (msg.equals(m.getSummary()) || msg.equals(m.getDetail())) {
                            return;
                        }


                    fail(allmsg+ " no msg for component '" + cptid + "'  msg=" + msg);
                }

            • 3. Re: How to test input & rich:ajaxValidator event="onblur" & rich:message
              ssilvert

              I figured it would take something like that.  Thanks for sharing your solution.

               

              Stan