JSF composite component childrens

最后都变了- 提交于 2019-12-11 10:31:52

问题


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?


回答1:


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?




回答2:


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!



来源:https://stackoverflow.com/questions/4999720/jsf-composite-component-childrens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!