当包含ajax关闭事件侦听器时,Primefaces对话框不会重新打开

bil*_*lyg 2 java primefaces jsf-2

我想以编程方式控制何时显示和隐藏对话框.它的工作原理除非使用'X'关闭对话框并且添加了ajax close事件监听器.例如,在下面的代码中使用'X'关闭对话框,如果我注释掉ajax线,则使用按钮多次显示/重新打开.

顺便说一句:我已经看到了使用oncomplete方法调用欺骗的javascript选项.

<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);
}
}
Run Code Online (Sandbox Code Playgroud)

Primefaces 3.5,JSF 2.0.7,Tomcat 7

Mr.*_*mes 6

我认为更新visible属性不是打开/关闭对话框的正确方法.它应该是这样的:

RequestContext context = RequestContext.getCurrentInstance();
context.execute("dlg.show();"); // To open the dialog
context.execute("dlg.hide();"); // To close the dialog
Run Code Online (Sandbox Code Playgroud)