title: Open and close a dialog many times with Primefaces DialogFramework
body: <p>i have a problem using the Dialog Framework of Primefaces.
  (WildFly 8.2, Primefaces 5.3.12, Java 8, Eclipse 4.3.2, Ubuntu 14.04, Firefox/Chrome)</p>
  
  <p>If i open a dialog with :</p>
  
  <pre><code> RequestContext.getCurrentInstance().openDialog(...);
  </code></pre>
  
  <p>and then close it with :</p>
  
  <pre><code>RequestContext.getCurrentInstance().closeDialog(null);
  </code></pre>
  
  <p>The dialog is closed, but now if i try to open it again, nothing happen. 
  If i look in the Firefox console i can see a JavaScript error just after le dialog is closed :</p>
  
  <pre><code>TypeError: dlgWidget is undefined
  PrimeFaces.dialog.DialogHandler.closeDialog()
  primefaces.js.xhtml:6
  b.closeDialog()
  primefaces.js.xhtml:1
  &lt;anonyme&gt;
  jquery.js.xhtml:1
  .globalEval/&lt;()
  jquery.js.xhtml:14
  .globalEval()
  jquery.js.xhtml:14
  PrimeFaces.ajax.ResponseProcessor.doEval()
  primefaces.js.xhtml:3
  PrimeFaces.ajax.Response.handle()
  primefaces.js.xhtml:3
  PrimeFaces.ajax.Request.send/q.success()
  primefaces.js.xhtml:3
  bH.Callbacks/i()
  jquery.js.xhtml:25
  bH.Callbacks/cc.fireWith()
  jquery.js.xhtml:25
  cf()
  jquery.js.xhtml:25
  .send/i()
  jquery.js.xhtml:25
  primefaces.js.xhtml:6:3190
  </code></pre>
  
  <p>in the primefaces.js this seems to be this code :</p>
  
  <pre><code>closeDialog : function(cfg) {
      var rootWindow = this.findRootWindow(), 
      dlgs = $(rootWindow.document.body).children('div.ui-dialog[data-pfdlgcid="' + cfg.pfdlgcid + '"]').not("[data-queuedforremoval]"),
      dlgsLength = dlgs.length, 
      dlg = dlgs.eq(dlgsLength - 1), 
      parentDlg = dlgsLength &gt; 1 ? dlgs.eq(dlgsLength - 2) : null, 
      dlgWidget = rootWindow.PF(dlg.data("widgetvar")), 
      sourceWidgetVar = dlgWidget.cfg.sourceWidgetVar,
   ....
  </code></pre>
  
  <p>I've 2 different behaviors :</p>
  
  <ul>
  <li><p>When i work in Eclipse, there is no error (i can open/close the dialog many times without any problem)</p></li>
  <li><p>When my software is compiled and deployed (WAR in an EAR) i've got the problem with the Dialog Framework. If i close the dialog with the cross on the right top (not my commandButton) there is no problem.</p></li>
  </ul>
  
  <p>Do you have any ideas about what is going wrong when it's deployed ?
  Thank you for your help.</p>
  
  <p>Managed bean</p>
  
  <pre><code>@ManagedBean
  @ViewScoped  
  public class FamilleArticlesController { 
  
  public void actFermerDialog(ActionEvent actionEvent) {
      RequestContext.getCurrentInstance().closeDialog(null);
  }
  
  public void actDialogTypes(ActionEvent actionEvent) {
  
      Map&lt;String,Object&gt; options = new HashMap&lt;String, Object&gt;();
      options.put("modal", true);
      options.put("draggable", true);
      options.put("resizable", false);
      options.put("contentHeight", 320);
  
      Map&lt;String,List&lt;String&gt;&gt; params = new HashMap&lt;String,List&lt;String&gt;&gt;();
      List&lt;String&gt; list = new ArrayList&lt;String&gt;();
      list.add(modeEcran.modeString(EnumModeObjet.C_MO_INSERTION));
      params.put("modeEcranDefaut", list);
  
      RequestContext.getCurrentInstance().openDialog("articles/dialog_type_famille_article", options, params);
  
  }
  
  public void handleReturnDialogTypes(SelectEvent event) {
      if(event!=null &amp;&amp; event.getObject()!=null) {
      }   
  }
  }
  </code></pre>
  
  <p>Dialog template : dialog_type_famille_article.xhtml</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
  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;title&gt;Type famille d'Article&lt;/title&gt;
      &lt;style type="text/css"&gt;
          .ui-widget {
              font-size: 90%;
          }
      &lt;/style&gt;
  &lt;/h:head&gt;
  
  &lt;h:body&gt;
      &lt;h:form id="idDialogFamilleArticle"&gt;    
          &lt;ui:include src="famille_articles.xhtml"/&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Dialogue include : famille_articles.xhtml</p>
  
  <pre><code>&lt;ui:composition 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;p:panel id="familleDataTableF" class="mt30 bg-grey"&gt;
  
  
          &lt;p:commandButton id="idInsererFamilleArticle" value="Ajouter" title="Insérer" process="@this"
          update=":form:tabView,:form:messages,:form" 
              actionListener="#{familleArticlesController.actDialogTypes}"
              styleClass="icon-insert icon" &gt;
              &lt;p:ajax event="dialogReturn" listener="#{familleArticlesController.handleReturnDialogTypes}" 
                  update=":form"/&gt;
          &lt;/p:commandButton&gt;
   &lt;/p:panel&gt;
  
   &lt;p:panel&gt;
  &lt;p:commandButton id="familleArticlesAnnulerDialogue" 
  value="Annuler"
      styleClass="btn-cancel btn" process="@this"
      disabled="#{familleArticlesAnnulerController.etatBouton('annuler')}"
      actionListener="#{familleArticlesController.actFermerDialog}"
      rendered="#{dansDialogue != null ? true : false}" /&gt;
  
  &lt;/p:panel&gt;
   &lt;/ui:composition&gt;
  </code></pre>