billyg
billyg

Reputation: 23

Primefaces Dialog not reopening when ajax close event listener included

I would like to programmatically control when a dialog is showed and hidden. It's works except when the dialog is closed using 'X' and and ajax close event listener is added. For example in the code below close dialog using 'X' and show/reopen many times using the button if I comment out the ajax line.

BTW: I have seen the javascript option which is tricked using oncomplete method call.

<h:form>
Status: <h:outputText id="status" value="#{helloBean.visible}" />
<p />

<p:dialog id="myDialog" header="Header Text" widgetVar="dlg" visible="#{helloBean.visible}">
<p:ajax event="close" listener="#{helloBean.hide}" update="myDialog" />

<h1>Dialog content ....</h1>

  <p:commandButton value="Hide" actionListener="#{helloBean.hide}" update="myDialog status" />
</p:dialog>

<p:commandButton value="Show" actionListener="#{helloBean.show}" update="myDialog status" />            
</h:form>


@ManagedBean
@ViewScoped
public class HelloBean implements Serializable {

private static final long serialVersionUID = 1L;
private boolean visible;

public boolean isVisible() {
  return visible;
}

public void setVisible(boolean visible) {
  this.visible = visible;
}

public void show() {
  setVisible(true);
  System.err.println("show(): " + visible);
}
public void hide() {
  setVisible(false);
  System.err.println("hide(): " + visible);
}
}

Primefaces 3.5, JSF 2.0.7, Tomcat 7

Upvotes: 2

Views: 6438

Answers (1)

Mr.J4mes
Mr.J4mes

Reputation: 9266

I think updating the visible attribute is not a correct way to open/close a dialog. It should be something like this:

RequestContext context = RequestContext.getCurrentInstance();
context.execute("dlg.show();"); // To open the dialog
context.execute("dlg.hide();"); // To close the dialog

Upvotes: 6

Related Questions