如何在运行时有条件地包含 jsf facelets 文件?
所需的示例功能是
if ( add button click) {
ui:include src="Add.xhtml"
}
if ( update button click) {
ui:include src="Update.xhtml"
}
上面的语法只是指示性的......
Mojarra 2.1.1/Apache Tomcat 7.0.22/PrimeFaces 3.4
最佳答案
ui:include
没有 rendered
属性,因此您必须将其封装在其他组件中。此外,您将根据单击的按钮在服务器上设置一些属性。
<h:form>
<p:commandButton value="Add" update=":includeContainer">
<f:setPropertyActionListener value="add" target="#{myBean.action}"/>
</p:commandButton>
<p:commandButton value="Update" update=":includeContainer">
<f:setPropertyActionListener value="update" target="#{myBean.action}"/>
</p:commandButton>
</h:form>
<h:panelGroup id="includeContainer">
<h:panelGroup rendered="#{myBean.action == 'add'}">
<ui:include src="add.xhtml"/>
</h:panelGroup>
<h:panelGroup rendered="#{myBean.action == 'update'}">
<ui:include src="update.xhtml"/>
</h:panelGroup>
</h:panelGroup>
在支持 bean 中,您将拥有 getter 和 setter:public void setAction(String action) {
this.action = action;
}
public String getAction() {
return action;
}
关于dynamic - 条件jsf包括,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15197961/