2
votes

In JSP and JSTL I would normaly do something like this:

<c:forEach items="${userList}" var = "user">
    <div id = "user-block">
        <h1>${user.name}</h1>
        <div id = "user-description">
            <p>${user.description}</p>
        </div>
        <ul>
            <li> Age: ${user.age} </li>
            <li> City: ${user.city} </li>
            <li> Country: ${user.country} </li>
        </ul>
    </div>
</c:forEach>

I'm trying to gain the same result using Facelet Composite Components:

<cc:interface>
    <cc:attribute name="value" type="java.util.List" required="true" shortDescription="The list of objects that should be displayed"/>
</cc:interface>

<cc:implementation>
    <div class = "event-block">

    </div>
</cc:implementation>

The problem is that I don't know how to iterate over the objects in #{cc.attrs.value}.

LE: I would like to know if there is a way to solve this without using JSP or JSTL

2
@informatik: please stop tagging JSF questions as [java] when the question doesn't concern a basic Java code/language problem (which in turn is essentially unrelated to JSF then). This prevents [java] nitwits who are downvoting questions they didn't understand and/or posting nonsensicial comments/answers (and this also prevents default XML/XHTML syntax highlighting being messed up due to higher precedence of [java] tag).BalusC
@BalusC Oh, I see. Will take into considerationinformatik01

2 Answers

8
votes

Use ui:repeat instead of c:forEach.

<ui:repeat value="#{cc.attrs.value}" var="user">
    <h1>#{user.name}</h1>
    ...
</ui:repeat>

See https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat for further comparison of c:forEach and ui:repeat.

0
votes

You can refer to the list with #{cc.attrs.value}. It would be something like:

<c:forEach items="${cc.attrs.value}" var = "user">
   // do your thing
</c:forEach>