【发布时间】:2013-03-07 01:01:39
【问题描述】:
我实际上是在尝试创建自定义复合表组件,因为 h:datatable 或 p:datatable 不符合我的需要。然而,它应该像 primefaces 数据表一样使用。 在我找到JSF composite component childrens之后 和 Expose items of a list while iterating within composite component我看到了终点,现在卡住了。
我的xhtml:
<h:body>
<sm:datatable mode="columntoggle" id="mytable" value="#{managerBean.objects}" var="object">
<sm:column header="KeyHeader" property="key">
<h:outputText value="#{object.key}"/>
</sm:column>
<sm:column header="ValueHeader" property="value">
<h:outputText value="#{object.value}"/>
</sm:column>
</sm:datatable>
</h:body>
这是数据表组合:
<cc:interface>
<cc:attribute name="id" />
<cc:attribute name="mode" />
<cc:attribute name="var" />
<cc:attribute name="value" type="java.util.List"/>
</cc:interface>
<cc:implementation>
<table data-role="table" data-mode="#{cc.attrs.mode}" id="my-table">
<thead>
<tr>
<ui:repeat value="#{component.getCompositeComponentParent(component).children}" var="child">
<th>
<h:outputText value="#{child.attrs.header}"/>
</th>
</ui:repeat>
</tr>
</thead>
<tbody>
<ui:repeat value="#{cc.attrs.value}" var="object">
<tr>
<c:forEach items="#{cc.children}" var="child" varStatus="loop">
<cc:insertChildren/>
</c:forEach>
</tr>
</ui:repeat>
</tbody>
</table>
</cc:implementation>
这就是列组合
<cc:interface>
<cc:attribute name="header" />
<cc:attribute name="property" />
<cc:facet name="content"/>
</cc:interface>
<cc:implementation>
<td><cc:insertChildren/></td>
</cc:implementation>
头独立工作
tbody 独立工作
像上面那样把它们放在一起,我只能得到 tbody。标题总是空着有什么建议吗? 感谢您提前提供的帮助!
【问题讨论】:
-
<table id="my-table- 绕过 JSF 的 id 命名空间。一般来说:不要这样做——你应该只为 JSF 组件设置 id,而不是基本的 HTML 标记。在这种情况下,在复合组件中,您应该有一个顶级的基本 HTML 标记,但将其 id 设置为#{cc.clientId}。这样update="your_comp"就可以了。
标签: jsf nested components children composite