3 Replies Latest reply on Sep 6, 2010 11:10 AM by Ilya Shaikovsky

    trouble with <rich:inplaceInput> validator message

    Akshay Jain Newbie

      Following is the jspx code for inplaceinput:

       

      <rich:inplaceInput defaultLabel="User ID" id="externalNodeId" value="#{nodeFlowBean.nodeVo.externalNodeId}" layout="block" controlsHorizontalPosition="left" inputWidth="200%" validator="#{nodeFlowBean.validateUserId }">
           <rich:ajaxValidator event="onblur"/>
           </rich:inplaceInput>
      <rich:message for="externalNodeId"/>

       

      And following is the validator code insisde nodeFlowBean:

       

      public void validateUserId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent comp, Object value)
          {
              System.out.println(context);
              System.out.println(comp);
              System.out.println(value);
              context.addMessage("externalNodeId", new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid","Invalid"));
          }

       

      Next is the server console output:

       

      org.springframework.faces.webflow.Jsf2FlowFacesContext@a174bc
      org.richfaces.component.html.HtmlInplaceInput@1f6f988
      dddadadsfsd

       

      Now problem is that the message that I add to FacesContext is not shown on webpage by <rich:message for="externalNodeId"/>

       

      So what am I missing here?

        • 1. Re: trouble with <rich:inplaceInput> validator message
          Ilya Shaikovsky Master

          according to API docs

           

              /**
               * <p>Append a {@link javax.faces.application.FacesMessage} to the set of messages associated with
               * the specified client identifier, if <code>clientId</code> is
               * not <code>null</code>.  If <code>clientId</code> is <code>null</code>,
               * this {@link javax.faces.application.FacesMessage} is assumed to not be associated with any
               * specific component instance.</p>
               *
               * @param clientId The client identifier with which this message is
               *  associated (if any)
               * @param message The message to be appended
               *
               * @throws IllegalStateException if this method is called after
               *  this instance has been released
               * @throws NullPointerException if <code>message</code>
               *  is <code>null</code>
               */
              public abstract void addMessage(String clientId, FacesMessage message);

          you should use clientId.

           

          so use like:

          public void validateUserId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent comp, Object value)
              {
                  System.out.println(context);
                  System.out.println(comp);
                  System.out.println(value);
                  context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR,"Invalid","Invalid"));
              }
          • 2. Re: trouble with <rich:inplaceInput> validator message
            Akshay Jain Newbie

            Ok this solves the problem. But now I face another very peculiar problem. As shown above in code the validator is applied to a inplaceInput. So what is happening is this:

             

            1. Load page.

            2. Click on inplaceInput and type something (say '123' )

            3. Tab out of control

            4. No Message

             

            5. Click on inplaceInput once again and type something diferrent (say '456' )

            6. Tab out

            7. Message displayed

             

            That is when page is loaded first time and inplaceInput recieves and loses focus first time the validation does not occur at all because no output on console as per validation method that i shown above.

             

            below is console output upon first tab out:

            01-Sep-2010 21:33:05 org.slf4j.impl.JCLLoggerAdapter info
            INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.

             

            upon second tab out the output is as follows:

            org.springframework.faces.webflow.FlowFacesContext@1e95e9e
            org.richfaces.component.html.HtmlInplaceInput@430322
            123
            01-Sep-2010 21:34:00 com.sun.faces.lifecycle.RenderResponsePhase execute
            INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.

             

            that is when it is second time tab out then it does validation for first value.

             

            Why?? What is wrong??

            • 3. Re: trouble with <rich:inplaceInput> validator message
              Ilya Shaikovsky Master

              use not onblur but onviewactivated event. and check this thread to get code which will help to optimize number of calls.