实际上我在使用带内容动态的Dialog时出现问题,当我提出一个commandButton我希望出现一个Dialog,但内容的对话框没有出现
XHTML
</p:treeTable>
<p:commandButton value="Add" action="#{showEn.displaySelectedNode}" oncomplete="PF('dialogWidget').show()"/>
</h:form>
<p:dialog appendTo="@(body)" id="dialog" widgetVar="dialogWidget">
<ui:include src="#{showEn.dialog}"/>
</p:dialog>
爪哇
public void displaySelectedNode(){
if(!dialogs[0].equals("-")){
this.dialog="addEn.xhtml";
}else if(!dialogs[1].equals("-")){
this.dialog="addCu.xhtml";
}else if(!dialogs[2].equals("-")){
this.dialog="addTa.xhtml";
}
}
public String getDialog() {
return dialog;
}
public void setDialog(String dialog) {
this.dialog = dialog;
}
答案 0 :(得分:0)
必须包装对话框标记,然后更新包装器。
<h:panelGroup id='wrapper' >
<p:dialog appendTo="@(body)" id="dialog" widgetVar="dialogWidget"
dynamic="true" /* given that the src is evaluated during the build phase,
the use of dynamic content offer a second update
*/>
<ui:include src="#{showEn.dialog}"/>
</p:dialog>
</panelGroup>
<p:commandButton value="Add" action="#{showEn.displaySelectedNode}"
oncomplete="PF('dialogWidget').show()" update="wrapper" />
此解决方案的问题是,如果已加载对话框,内容将不会更改
我建议尝试这个解决方案:
java
private boolean urlChanged;
public boolean isUrlChanged(){
if (urlChanged){
urlChanged = false;
return true;
}
return false;
}
public void displaySelectedNode(){
urlChanged = true;
if(!dialogs[0].equals("-")){
this.dialog="addEn.xhtml";
}else if(!dialogs[1].equals("-")){
this.dialog="addCu.xhtml";
}else if(!dialogs[2].equals("-")){
this.dialog="addTa.xhtml";
}
}
XHTML
<p:dialog appendTo="@(body)" id="dialog" widgetVar="dialogWidget"
dynamic="false" /* no need for that */>
<h:panelGroup id='wrapper' >
<p:remoteCommand name="updateAgain" update="wrapper"/>
<c:if test="#{showEn.isUrlChanged}"><script>updateAgain();</script></c:if>
<ui:include src="#{showEn.dialog}"/>
</panelGroup>
</p:dialog>
<p:commandButton value="Add" action="#{showEn.displaySelectedNode}"
oncomplete="PF('dialogWidget').show()" update="wrapper" />
答案 1 :(得分:0)
最后我已经取得了很好的工作,问题是我正在使用primefaces 5的primefaces版本,这个麻烦的正确版本是primefaces版本4.无论如何,谢谢。 ;)