简体   繁体   English

替换c:foreach on ui:repeat

[英]Replace c:foreach on ui:repeat

I use JSF2 and primefaces. 我使用JSF2和primefaces。 I have this piece of code 我有这段代码

<c:forEach begin="1" end="5" var="i">
    <h:outputLabel value="#{i} #{msg.set}:"/>
</c:forEach>

Is it possible replace with ui:repeat without creating list items in range from 1 to 5? 是否可以用ui:repeat替换而不创建1到5范围内的列表项?

You may be able to get away with constructing an inline list with spel 您可以通过使用spel构建内联列表来逃脱

http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/expressions.html http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/expressions.html

<ui:repeat var="i" value="#{1,2,3,4,5}">
    <h:outputLabel value="#{i} #{msg.set}:"/>
</ui:repeat>

But may be unwieldy if you need hundreds. 但如果你需要数百个,可能会很笨拙。

I think you would have to create a backing bean of some sort to be more flexible. 我认为你必须创建一种更灵活的支持bean。

It could be made as a seperate utility bean that has a method the returns a List of integers i guess to help out so you could call 它可以作为一个单独的实用程序bean,有一个方法返回一个整数List我猜想帮助你所以你可以调用

<ui:repeat var="i" value="#{util.generate(1,5)}">
    <h:outputLabel value="#{i} #{msg.set}:"/>
</ui:repeat>

No. The ui:repeat tag is not a general iterating tag, but works with collections only. 不可以.ui:repeat标签不是一般的迭代标签,但仅适用于集合。

You'll have to use forEach, or design around this. 你必须使用forEach,或围绕这个设计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM