dynamic - 条件jsf包括

标签 dynamic jsf-2 user-interface include

如何在运行时有条件地包含 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/

相关文章:

django - Django模型继承层次结构中字段的基于类的默认值

ruby - 在类声明后设置类继承或在 const_set 类上设置类继承

c++ - wxWidgets 在 wxPanel 上绘制 wxGLCanvas

python - 在 Traitsui GUI 之外更改属性

c++ - 在Allegro5中绘制部分图像/字体

elasticsearch - 使用动态字段名称搜索ElasticSearch

Python:动态实例化

java - JSF 2 - 存在哪些方法可以返回到调用页面?

java - JSF 2 - @ViewScoped bean 在请求之间存在于何处?

jsf - 在JSF中何时以及如何生成clientID?