title: Primefaces hide and unhide dialog
body: <p>right now I'm studying the primefaces the UI is incredible and I want to use it to build my website so right now I'm studying the dialog box and I want to hide and unhide dialog box using the requestcontext of the primefaces how can I achieve this? I search the stackoverflow for the same question and I found a few but it is not working on me, to make everything clear this is my register.jsf code: </p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:p="http://primefaces.org/ui"&gt;
  &lt;h:head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
      &lt;title&gt;Insert title here&lt;/title&gt;
      &lt;h:outputStylesheet library="css" name="style.css"/&gt;
  &lt;/h:head&gt;
  &lt;h:body&gt;
      &lt;p:panel toggleable="true" header="Registration" closable="true" closeTitle="back" styleClass="register-panel"&gt;
          &lt;h:form&gt;
              &lt;h:panelGrid columns="2"&gt;
                  &lt;h:outputLabel  value="Firstname: " /&gt;
                  &lt;p:inputText id="firstname" value="#{ register.firstName }" required="true" requiredMessage="Firstname cannot be blank"&gt;
                      &lt;f:validateDoubleRange minimum="3" maximum="15"  /&gt;
                  &lt;/p:inputText&gt;
  
                  &lt;h:outputLabel value="Middlename: " /&gt;
                  &lt;p:inputText id="middlename" value="#{ register.middleName }" required="true" requiredMessage="Middlename cannot be blank"&gt;
                      &lt;f:validateDoubleRange minimum="3" maximum="15"  /&gt;
                  &lt;/p:inputText&gt;
  
                  &lt;h:outputLabel value="Lastname: " /&gt;
                  &lt;p:inputText id="lastname" value="#{ register.lastName }" required="true" requiredMessage="Lastname cannot be blank"&gt;
                      &lt;f:validateDoubleRange minimum="3" maximum="15"  /&gt;
                  &lt;/p:inputText&gt;
  
                  &lt;p:commandButton type="button" update="errorFirst, errorMiddle, errorLast, ErrorD, confirmD" value="Register" actionListener="#{ register.Register }" /&gt;
  
                  &lt;p:dialog width="350"  modal="true" id="ErrorD" header="Error Registration" visible="true" maximizable="false"  widgetVar="showErrorDialog"&gt;
                  &lt;h:panelGrid columns="1"&gt;
                      &lt;p:message for="firstname" id="errorFirst" /&gt;
                      &lt;p:message for="middlename" id="errorMiddle" /&gt;
                      &lt;p:message for="lastname" id="errorLast" /&gt;
                  &lt;/h:panelGrid&gt;
                  &lt;/p:dialog&gt;
  
                  &lt;p:dialog width="350" modal="true" id="confirmD" header="Confirm Registration"  visible="true" maximizable="false"  widgetVar="showConfirmDialog"&gt;
                      &lt;h:panelGrid columns="2"&gt;
                          &lt;h:outputLabel value="Are you sure you want to save the records" /&gt;
                          &lt;h:outputLabel value=""/&gt;
                          &lt;p:separator /&gt;
                          &lt;p:separator /&gt;
  
                          &lt;p:commandButton value="Ok, Sure" /&gt;
                          &lt;p:commandButton value="Cancel" /&gt;
                      &lt;/h:panelGrid&gt;
  
                  &lt;/p:dialog&gt;
  
              &lt;/h:panelGrid&gt;
  
          &lt;/h:form&gt;
      &lt;/p:panel&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and this is my register bean:</p>
  
  <pre><code>    package org.register;
  
  import javax.annotation.PostConstruct;
  import javax.faces.bean.*;
  import javax.faces.event.ActionEvent;
  import org.primefaces.context.RequestContext;
  
  @ManagedBean(name="register")
  @RequestScoped
  public class registerBean {
  
      private String firstName;
      private String middleName;
      private String lastName;
  
      public String getFirstName() {
          return firstName;
      }
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      public String getMiddleName() {
          return middleName;
      }
      public void setMiddleName(String middleName) {
          this.middleName = middleName;
      }
      public String getLastName() {
          return lastName;
      }
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
  
      public void Register(ActionEvent e){
          RequestContext primeContext = RequestContext.getCurrentInstance();
          if(getFirstName().equals("") || getMiddleName().equals("") || getLastName().equals("")){
              primeContext.execute("showErrorDialog.show()");
          }
          else{
              primeContext.execute("showConfirmDialog.show()");
          }
  
      }
  
  
  }
  </code></pre>
  
  <p>I don't have any error on my code but the problem is everytime the page load, it call already the 2 dialog, what I want to do is open the first dialog if registration fail and open the second dialog when it is success. thanks guys.</p>