title: To display validation message in primefaces dialog from managed bean
body: <p>i am trying to display the message of the outcome of a validation done in managed bean in the dialog but it is not getting displayed in the dialog on submit of the form.</p>
  
  <p>Please help me in fixing this</p>
  
  <p>My JSF page snippet with dialog</p>
  
  <pre><code>&lt;p:dialog header="Add LPC" id="lpcDlg" widgetVar="dlg" rendered="true"
            appendToBody="true" resizable="true" modal="true" height="320px"
            width="38%"&gt;
      &lt;h:form id="addLpc"&gt;
          &lt;div align="center" style="margin-bottom: 1px; padding-bottom: 1px;"&gt;
              &lt;h:outputLabel value="Add New LPC"
                             style="font-color:#000000;font-weight:bold;font-size:24px;padding-bottom:1px;"&gt;&lt;/h:outputLabel&gt;
          &lt;/div&gt;
  
          &lt;div align="center"&gt;
  
              &lt;p:messages id="lpcDlgMsg" showDetail="false" autoUpdate="true"
                          closable="true" /&gt;
              &lt;p:messages id="lpcDlgMsg2" for="lpcDlgMessage" showDetail="false"
                          autoUpdate="true" closable="true" /&gt;
              &lt;h:panelGrid id="addLpcForm" columns="2" appendToBody="true"&gt;
  
                  &lt;h:outputText value="LPC ID" /&gt;
                  &lt;p:inputText id="lpcId" value="#{lpcBean.lpcId}" required="true"
                               requiredMessage="LPC ID is required"&gt;
                      &lt;f:ajax event="blur" render="lpcDlgMsg" /&gt;
                  &lt;/p:inputText&gt;
  
                  &lt;h:outputText value="First Name" /&gt;
                  &lt;p:inputText id="firstName" value="#{lpcBean.firstName}" /&gt;
                  .
                  .
                  .
                  .
              &lt;/h:panelGrid&gt;
          &lt;/div&gt;
          &lt;div align="center"&gt;
              &lt;p:commandButton id="submitButton" value="Submit" ajax="true"
                               update=":lpcForm:lpcDataTable,addLpc"
                               action="#{lpcBean.formSubmit}" oncomplete="dlg.hide()" /&gt;
              &lt;p:commandButton id="cancelButton" value="Cancel" 
                               onclick="dlg.hide()" /&gt;
  
          &lt;/div&gt;
      &lt;/h:form&gt;
  &lt;/p:dialog&gt;
  </code></pre>
  
  <p>message with id <strong>lpcDlgMsg2</strong> is the message i am trying to display on submit.The other message is getting displayed correct on blur.</p>
  
  <p>Snippet of the method that is called on submit</p>
  
  <pre><code>public void formSubmit()
  
  {
          if(resultSet.next())
          {
  
              int lpcIdCount=rs.getInt("lpcCount");
              if(lpcIdCount!=0)
              {
                  FacesContext.getCurrentInstance().addMessage("lpcDlgMessage", new FacesMessage(FacesMessage.SEVERITY_ERROR," ", "Duplicate LPCID"));
                  System.out.println("after display");
              }
              else
              {
                  .
                  .
                  .
                  .
              }
  
          }
      }   
  
  }
  </code></pre>