JSF Iterative Composite Component with Custom Content

I want to create a composite component to which you can pass the layout of repeating elements. This is a simplified example and works:

<composite:interface>
    <composite:attribute name="value"/>
</composite:interface>

<composite:implementation>
    <ul>
        <c:forEach var="i" items="#{cc.attrs.value}">
            <li>
                <h:outputText value="Test #{i.name}"/>
            </li>
        </c:forEach>
    </ul>

But I do not want to h:outputTextbe hardcoded in the component. When using the component, I try to do something like this:

<my:list var="user" value="#{myBean.userList}">
  <h:outputText value="Test #{user.name}"/>
</my:list>

Suppose I need to use var, but I don’t know how to handle this in my component and get the child correctly <h:outputText value="Test #{user.name}"/>.

+3
source share
1 answer

<composite:insertChildren />, "" , . <ui:repeat> <c:forEach>, JSF. :

<composite:interface>
    <composite:attribute name="value"/>
</composite:interface>

<composite:implementation>
  <ul>
     <ui:repeat var="item" value="#{cc.attrs.value}">
       <li>
           <composite:insertChildren />
       </li>
     </ui:repeat>
  </ul>
</composite:implementation>

:

<my:list value="#{myBean.userList}">
  <h:outputText value="Test #{item.name}"/>
</my:list>
+4

All Articles