JSF composite component childrens
Asked Answered
V

2

1

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?

Vollmer answered 15/2, 2011 at 3:49 Comment(2)
May be I didnt understand the question correctly. Can you not just use nested ui:repeat?Zambrano
I can, but My question is regarding how to get a composite component's children components. Once I get the list of children components I can iterate through them but how do I get that list?Vollmer
I
2

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?

Ibeam answered 15/2, 2011 at 10:16 Comment(1)
I know that the children has a title attribute, how do I access it? the child.title doesnt workVollmer
B
0

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!

Bambara answered 21/9, 2016 at 15:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.