Search code examples
javajsfjsf-2uirepeat

Replace c:foreach on ui:repeat


I use JSF2 and 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?


Solution

  • You may be able to get away with constructing an inline list with spel

    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.

    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

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