ust*_*tun 20
从Facelets 2.0开始,现在可以使用varStatus.
<ui:repeat varStatus="status" var="user" value="#{collection}">
#{status.index}
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
Boz*_*zho 11
由于你使用的是richfaces,你可以使用它的迭代标记(<a4j:repeat>),它比使用更合适,它就<c:forEach>像是一个扩展<ui:repeat>
<table>
<a4j:repeat value="#{bean.list}" var="item" rowKeyVar="idx">
<tr>
<td><h:outputText value="#{idx + 1}" /></td>
<td><h:outputText value="#{item.someProperty}" /></td>
<td><h:outputText value="#{item.otherProperty}" /></td>
</tr>
</a4j:repeat>
</table>
Run Code Online (Sandbox Code Playgroud)
你不能很好地做到这一点ui:repeat,但你可以这样做h:dataTable.将组件绑定到UIData辅助bean中的属性.它有一种getRowIndex()方法可以完全满足您的需求:
<h:dataTable binding="#{bean.table}" value="#{bean.list}" var="item">
<h:column><h:outputText value="#{bean.table.rowIndex + 1}" /></h:column>
<h:column><h:outputText value="#{item.someProperty}" /></h:column>
<h:column><h:outputText value="#{item.otherProperty}" /></h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)
我在这里添加1,UIData#getRowIndex()因为它是从零开始的.您可能会发现使用数据表文章有助于了解有关数据表的更多信息.
如果你真的想要更多地控制表格布局(特别是使用真正的JSF h:dataTable标签中缺少的colspans/rowspans ),那么另一种方法是使用JSTL c:forEach标签,该标签具有一个varStatus属性,可以为循环提供句柄状态.
<table>
<c:forEach items="#{bean.list}" var="item" varStatus="loop">
<tr>
<td><h:outputText value="#{loop.index + 1}" /></td>
<td><h:outputText value="#{item.someProperty}" /></td>
<td><h:outputText value="#{item.otherProperty}" /></td>
</tr>
</c:forEach>
</table>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21305 次 |
| 最近记录: |