如何使复合组件类似于< h:selectOneRadio/> [英] How to make composite component similar to <h:selectOneRadio />
问题描述
我一直在寻找制作类似于以下内容的复合组件的方法:<h:selectOneRadio />
但我没有成功.
I have been searching a lot for a way to make a composite component similar to: <h:selectOneRadio />
but I did not succeed.
我想要类似的东西:
<myowntags:selectOneRadio>
<f:selectItem itemValue="value0" itemLabel="This is the value 0" />
<f:selectItem itemValue="value1" itemLabel="This is the value 1" />
<f:selectItem itemValue="value2" itemLabel="This is the value 2" />
</myowntags:selectOneRadio>
和:
<myowntags:selectOneRadio>
<f:selectItems value="#{controller.items}" />
</myowntags:selectOneRadio>
如您所见,我希望这个复合组件有一个子对象:<f:selectItem />
并按照我想要的方式呈现它.
As you can see, I want this composite component to have a child: <f:selectItem />
and render it the way I want.
谢谢.
推荐答案
您可以通过#{cc.children}
检查并对其进行迭代. #{cc}
是指当前的组合 UIComponent
实例,而该实例又具有
You could check and iterate over them by #{cc.children}
. The #{cc}
refers to the current composite UIComponent
instance which in turn has a getChildren()
method. You could do kind of an instanceof
check by checking the child's FQN (or simple name if that's sufficient) in the <cc:implementation>
:
<c:forEach items="#{cc.children}" var="child">
<c:set var="type" value="#{child['class'].simpleName}" />
<c:if test="#{type == 'UISelectItem'}">
<input type="radio" value="#{child.itemValue}" />#{child.itemLabel}<br/>
</c:if>
<c:if test="#{type == 'UISelectItems'}">
<c:forEach items="#{child.value}" var="item">
<input type="radio" value="#{item.value}" />#{item.label}<br/>
</c:forEach>
</c:if>
</c:forEach>
但是,您的下一个问题是收集提交的值.为此,您需要在<cc:interface componentType>
引用的背景UIComponent
中实现decode()
方法.或者,最好用Renderer
创建自定义UIComponent
.接替视图中Renderer
的工作很笨拙.
Your next problem is however collecting the submitted values. For that you'd need to implement the decode()
method in the backing UIComponent
which you reference by <cc:interface componentType>
. Or, better, create a custom UIComponent
with a Renderer
instead. Taking over the Renderer
's job in the view is clumsy.
这篇关于如何使复合组件类似于< h:selectOneRadio/>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!