【发布时间】:2015-12-30 02:05:33
【问题描述】:
Primefaces 5.0、JSF 2.2、Wildfly 8.1
以下用例:
- 单击视图中的命令按钮(带有一些参数)
- bean 方法在数据库中查找某些内容 - 如有必要,将显示 dialog1。在 dialog1 中有一个表单和一个命令按钮。
- dialog1 中的命令按钮被单击,bean 方法在数据库中查找某些内容。
- Dialog1 关闭并显示 dialog2,具体取决于 bean 方法的结果。
bean1.java:
public void buttonClicked() {
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("widgetVar", "dialog1");
options.put("id", "dlg1");
if(somethingTrue()) {
RequestContext.getCurrentInstance().openDialog("dialog1.xhtml", options, null);
}
}
一切都好。 Dialog1 出现。
dialog1.xhtml:
<h:body>
<h:form>
<p:commandButton value="Button" actionListener="#{bean2.dialog1ButtonClicked}" />
</h:form>
</h:body>
bean2.java:
public void dialog1ButtonClicked() {
Map<String, Object> options = new HashMap<>();
options.put("modal", true);
options.put("widgetVar", "dialog2");
options.put("id", "dlg2");
if(somethingTrue()) {
RequestContext.getCurrentInstance().openDialog("dialog2.xhtml", options, null);
}
}
dialog2.xhtml:
<h:body>
The operation was successful.
</h:body>
Dialog2 出现在 dialog1 中!
如何关闭对话框 1 并在对话框 1 中显示对话框 2?
我尝试在打开 dialog2 之前使用 Primefaces 对话框框架关闭 dialog1:
RequestContext.getCurrentInstance().closeDialog(null);
RequestContext.getCurrentInstance().openDialog("dialog2.xhtml", options, null);
Dialog2 不显示。
我尝试在 AJAX 回调 <p:ajax event="dialogReturn" listener="#{bean1.dialogClosed}"/> 之后打开 dialog2
Dialog2 不显示。
我尝试了客户端 Java Script 调用:onclick="PF('dialog1').hide()"
Dialog2 仍然嵌套在 dialog1 中。
【问题讨论】:
-
为什么要打开带有第一个参数“dialog2.xhtml”的对话框,而不仅仅是展示中的“dialog2”?
-
您可以尝试使用
RequestContext.getCurrentInstance().execute("PF('dialogWidVar').show()")或RequestContext.getCurrentInstance().execute("PF('dialogWidVar').close()")关闭/显示服务器端的对话框 -
@JaqenH'ghar:两种方式的结果相同。我只是使用文件名来避免误解。
标签: jsf jsf-2 primefaces dialog