我最近开始使用带有Facelets的JSF 2.0,并且对于了解<ui:include>Facelets 1.x提供的现有和其他模板技术的新复合组件感到困惑.
这些方法有什么区别?从功能上看,它们似乎提供了相同的:<ui:param>vs <cc:attribute>,<ui:insert>+ <ui:define>vs标记文件,重用现有模板.除了复合组件的语法和清晰的接口规范之外还有什么吗?性能会有所不同?
我正在用Mojarra JSF编写自定义表复合组件.我也试图将该组合绑定到支持组件.目的是能够指定表在复合属性中具有的元素数量,稍后绑定的后备组件将在呈现视图之前自动生成元素本身.我有这个示例代码:
主页:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:comp="http://java.sun.com/jsf/composite/comp">
<h:head />
<body>
<h:form>
<comp:myTable itemNumber="2" />
</h:form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
myTable.xhtml:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">
<h:body>
<composite:interface componentType="components.myTable">
<composite:attribute name="itemNumber"
type="java.lang.Integer" required="true" />
</composite:interface>
<composite:implementation>
<h:dataTable value="#{cc.values}" var="value">
<h:column headerText="column">
#{value}
<h:commandButton value="Action" action="#{cc.action}" />
</h:column>
</h:dataTable>
</composite:implementation>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
MyTable.java:
@FacesComponent("components.myTable")
public class MyTable extends UINamingContainer {
private List<String> values = new ArrayList<String>();
public void action() {
System.out.println("Called");
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
// Initialize the list …Run Code Online (Sandbox Code Playgroud)