title: JSF: Dynamic include page into primefaces dialog
body: <p>I want to include the content of a primefaces dialog from another page with ui:include. The included page must be set dynamic depending on which button user clicked. I used the very helpful answer from BalusC from <a href="https://stackoverflow.com/questions/6219202/jsf-dynamic-include-using-ajax-request">JSF dynamic include using Ajax request</a>.</p>
  
  <p>It works very fine as in the example. But problems come if I use a p:dialog instead of h:panelGroup:</p>
  
  <pre><code>&lt;h:form&gt;
    &lt;f:ajax render=":dialog"&gt;
      &lt;p:commandButton value="page1" action="#{productBean.setDialogPage('/page1.xhtml')}" oncomplete="dialogWidget.show()"&gt;&lt;/p:commandButton&gt;
      &lt;p:commandButton value="page2" action="#{productBean.setDialogPage('/page2.xhtml')}" oncomplete="dialogWidget.show()"&gt;&lt;/p:commandButton&gt;
    &lt;/f:ajax&gt;
  &lt;/h:form&gt;
  &lt;p:dialog id="dialog" widgetVar="dialogWidget" &gt;
          &lt;ui:include src="#{productBean.dialogPage}" /&gt;
  &lt;/p:dialog&gt;
  </code></pre>
  
  <p>1st problem: Sometimes, I have to click a button several times before dialog appears. It seems not to follow any pattern but is a random effect. Sometimes I need to click twice, sometimes I need to click four times on the button.</p>
  
  <p>2nd problem: Sometimes, the dialog appears not with the selected page but with the old one. When I close dialog and select again, the current page is loaded. It seems to be a random effect, too.</p>
  
  <p>Why do I get this problems with dialog?</p>