arg20
arg20

Reputation: 4991

JSF composite component childrens

Is there any way using EL to retrieve a children list so i can iterate through it with

<ul>
   <ui:repeat value="#{Magic El expression}" var="children" >
      <li>
      <p> #{children.title} *</p>
      </li>
   </ui:repeat>
</ul>
<div>
 <cc:insertChildren />
</div>

* perhaps #{children.attrs.title} I don't know?

What I'm trying to do here is create a Tab composite component. I know libraries such as primefaces offer tabview etc. Yet I need to create my own because of extended jquery functionality. Plus I'm working with a specific template. I need to get the tabs title to create a list for tabs. Tabs are children components is there anyway i can iterate and fetch their attributes? I mean primefaces does that somehow.

If you look at their html markup they create an unordered list with the titles of each children tabview component. How is that implemented?

Upvotes: 1

Views: 5359

Answers (2)

Bill_BsB
Bill_BsB

Reputation: 314

If you Composite Component is an instance of : javax.faces.component.UINamingContainer Try this:

    <c:forEach items="#{cc.children}" varStatus="loop" var="child">
      loop[#{loop.index}]: #{child.getAttributes().get('title')}
    </c:forEach>

You can easily debug which instance are your JSF variables by printing them to the page like #{cc} or #{component}

Cheers!

Upvotes: 0

Arjan Tijms
Arjan Tijms

Reputation: 38163

If the markup you show is inside a composite component (I guess it is), then the following is the expression that will give you access to its children:

#{component.getCompositeComponentParent(component).children}

Slightly related question: In JSF2, how to know if composite component has children?

Upvotes: 2

Related Questions