2 Replies Latest reply on Aug 28, 2009 4:48 AM by Ilya Shaikovsky

    FacesMessages are not being displayed

    John Doe Newbie

      Hi!

      Consider the following example:

      <h:form>
       <a4j:outputPanel id="messagePanel" ajaxRendered="true">
       <h:messages for="myGrid" styleClass="errormsg" />
       </a4j:outputPanel>
      
       <h:panelGrid id="myGrid" columns="4" style="margin: 0px; padding: 0px;">
       <h:outputText value="stuff" />
       <a4j:commandLink value="#{aComponent.doSomething}" rerender="messagePanel" />
       </h:panelGrid>
      </h:form>


      And the method of the component:

      public void doSomething()
      {
       FacesMessage msg = new FacesMessage();
       msg.setSeverity(FacesMessage.SEVERITY_ERROR);
       msg.setDetail("A MESSAGE");
       FacesContext.getCurrentInstance().addMessage("myGrid", msg);
      }


      Why doesn't it display the message when clicking the commandLink? I am somewhat clueless and I can't use a messages tag, which works to my surprise.

      Please give me some insight.


        • 1. Re: FacesMessages are not being displayed
          John Doe Newbie

          *FIXT*

          Please ignore the first post.

          This forum needs an edit-function!

          Consider the following example:

          Code:

          <h:form>
          <a4j:outputPanel id="messagePanel" ajaxRendered="true">
          <h:message for="myGrid" styleClass="errormsg" />
          </a4j:outputPanel>

          <h:panelGrid id="myGrid" columns="4" style="margin: 0px; padding: 0px;">
          <h:outputText value="stuff" />
          <a4j:commandLink value="#{aComponent.doSomething}" rerender="messagePanel" />
          </h:panelGrid>
          </h:form>



          And the method of the component:

          Code:

          public void doSomething()
          {
          FacesMessage msg = new FacesMessage();
          msg.setSeverity(FacesMessage.SEVERITY_ERROR);
          msg.setDetail("A MESSAGE");
          FacesContext.getCurrentInstance().addMessage("myGrid", msg);
          }



          Why doesn't it display the message when clicking the commandLink? I am somewhat clueless and I can't use a messages tag, which works to my surprise.

          Please give me some insight.

          • 2. Re: FacesMessages are not being displayed
            Ilya Shaikovsky Master

             

             /**
             * <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 pass client Id to this method.