Jsf Primefaces对话框框架-打开对话框-关闭它-打开另一个对话框
Primefaces 5.0、JSF 2.2、Wildfly 8.1 以下用例:Jsf Primefaces对话框框架-打开对话框-关闭它-打开另一个对话框,jsf,jsf-2,primefaces,dialog,Jsf,Jsf 2,Primefaces,Dialog,Primefaces 5.0、JSF 2.2、Wildfly 8.1 以下用例: 单击视图中的命令按钮(带有一些参数) bean方法在数据库中查找某些内容-如果需要,将显示对话框1。对话框1中有一个窗体和一个命令按钮 单击dialog1中的命令按钮,bean方法将在数据库中查找某些内容 Dialog1关闭,dialog2根据bean方法的结果显示 bean1.java: public void buttonClicked() { Map<String, Object> op
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);
}
}
<h:body>
<h:form>
<p:commandButton value="Button" actionListener="#{bean2.dialog1ButtonClicked}" />
</h:form>
</h:body>
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);
}
}
<h:body>
The operation was successful.
</h:body>
对话2没有出现
我尝试在AJAX回调后打开dialog2
对话框2不显示
我尝试了客户端Java脚本调用:onclick=“PF('dialog1').hide()”
对话框2仍然嵌套在对话框1中显示。解决方案:
- 只打开一个对话框:
RequestContext.getCurrentInstance().openDialog(“dialog1.xhtml”,选项,null)代码>
- 对话框流由主面板的ajax更新控制,其中呈现的属性绑定到bean属性,因此完全由bean控制
@ManagedBean
@RequestScoped
public class Bean2 implements Serializable {
public void closeRegistration() {
FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("bean");
}
}
closeRegistration方法删除ViewScope bean。所以,在同一页面中再次调用该对话框将从一开始启动对话框流。使用
onHide
可以像这样打开另一个对话框
<p:dialog class="userRegisterDialog" header="#{bean.dailogHeader}" modal="true" resizable="false" draggable="false" onHide="PF('dialog2').show();>
</p:dialog>
我们也可以在onsuccess
或onerror
或oncomplete
中关闭对话框。检查图像以供参考为什么要用第一个参数“dialog2.xhtml”而不是showcase中的“dialog2”打开对话框?您可以尝试用RequestContext.getCurrentInstance().execute(“PF('dialogWidVar').show()”)关闭/显示服务器端的对话框
或RequestContext.getCurrentInstance().execute(“PF”)('dialogWidVar').close()
@JaqenH'ghar:两种方法的结果都是一样的。我只是使用了文件名以避免误解。但是使用这种解决方案,您没有决策路径!您的意思是您没有决策路径!
?@christ问题是,根据服务器端方法的结果显示不同的对话框。因此,您服务器端这样写RequestContext.getCurrentInstance().execute(“PF('dialog1').hide();PF('dialog2').show()”);
你试过这个吗?因为我想我试过了,但没有用。对话框仍然是嵌套的。请将代码和数据添加为文本(),而不是图像。图像:A)不允许我们复制和粘贴代码/错误/数据进行测试;B) 不允许基于代码/错误/数据内容进行搜索;和。如果图像添加了一些仅由文本代码/错误/数据无法传达的重要信息,则除了代码格式的文本外,还应使用图像。
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
@ManagedBean
@ViewScoped
public class Bean implements Serializable
{
private boolean showStep1 = true;
private boolean showStep2 = false;
public void doStep1(ActionEvent actionEvent) {
if(doSomething())
{
setShowStep1(false);
setShowStep2(true);
}
}
public void doStep2(ActionEvent actionEvent) {
if(doSomething2())
{
RequestContext.getCurrentInstance().closeDialog(null);
}
}
// Getter and setter ...
}
@ManagedBean
@RequestScoped
public class Bean2 implements Serializable {
public void closeRegistration() {
FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("bean");
}
}
<p:dialog class="userRegisterDialog" header="#{bean.dailogHeader}" modal="true" resizable="false" draggable="false" onHide="PF('dialog2').show();>
</p:dialog>