bun*_*udi 1 jsf icefaces richfaces facelets
请原谅我的头衔,这是我最近有限的大脑最好能够提出的.
所以,我有一个字符串列表,如[abc,def,ghi].
问题:在JSF中,我如何迭代列表并创建一个看起来像这个"abc,def,ghi"的字符串(注意逗号)?
对于那些有冲动告诉我我最好使用Java方法来连接字符串的人,请听一下:列表中的每个成员都应该作为单独的commandLink呈现.
如果普通的JSF看起来像:
<h:commandLink>abc</h:commandLink>, <h:commandLink>def</h:commandLink>, <h:commandLink>ghi</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
假设#{bean.items}回报率List<String>或String[]在JSF 1.x中,您可以使用JSTL c:forEach用varStatus.它为您提供了一个LoopTagStatus具有isLast()方法的句柄.
<c:forEach items="#{bean.items}" var="item" varStatus="loop">
<h:commandLink value="#{item}" /><c:if test="#{!loop.last}">, </c:if>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
在JSF 2.x附带的Facelets中,可以使用相同的功能ui:repeat.
<ui:repeat value="#{bean.items}" var="item" varStatus="loop">
<h:commandLink value="#{item}" />#{!loop.last ? ', ' : ''}
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3228 次 |
| 最近记录: |