具有可定制内容的JSF迭代复合组件 [英] JSF Iterative composite component with customizable content
问题描述
我想创建一个复合组件,其中迭代元素的实际布局可以传递给复合。
这是一个简化的例子,有效:
I want to create a composite component where to acutal layout of of iterating elements can be passed to the composite. 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>
但我不想要要在组件中进行硬编码的 h:outputText
。使用组件时,我试图这样:
But I don't want the h:outputText
to be hardcoded in the component. When using the component I'm trying to have something like this:
<my:list var="user" value="#{myBean.userList}">
<h:outputText value="Test #{user.name}"/>
</my:list>
假设我必须使用 var
,但我不知道如何处理我的组件和访问子< h:outputText value =Test#{user.name}/> ;
正确。
Is assume that I have to use a var
, but I don't know how to handle this in my component and access the child <h:outputText value="Test #{user.name}"/>
correctly.
推荐答案
您可以使用< composite:insertChildren />
来能够传递定义到复合组件定义的子组件。另外,我建议使用< ui:repeat>
而不是< c:forEach>
,因为它是一个真正的迭代组件并且更适合JSF。以下是如何实现组件的示例:
You could use <composite:insertChildren />
to be able to "pass" the child components defined to your composite component definition. Also I recommend using <ui:repeat>
instead of <c:forEach>
because it's a real iterative component and better suited for JSF. Here is an example how to implement your component:
<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>
这篇关于具有可定制内容的JSF迭代复合组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!