Jsf 2 如何使复合构件与<;h:selectOneRadio/>;

Jsf 2 如何使复合构件与<;h:selectOneRadio/>;,jsf-2,composite-component,Jsf 2,Composite Component,我一直在寻找一种使复合组件类似的方法: 但我没有成功 我想要像这样的东西: <myowntags:selectOneRadio> <f:selectItem itemValue="value0" itemLabel="This is the value 0" /> <f:selectItem itemValue="value1" itemLabel="This is the value 1" /> <f:selectItem itemValu

我一直在寻找一种使复合组件类似的方法:
但我没有成功

我想要像这样的东西:

<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>

以及:


如您所见,我希望这个复合组件有一个子组件:
,并以我想要的方式呈现它


提前感谢。

您可以通过
{cc.children}
检查并迭代这些文件。
#{cc}
引用当前的复合实例,该实例又有一个方法。您可以通过检查
中孩子的FQN(或简单名称,如果足够的话)来执行
实例检查:


#{child.itemLabel}
#{item.label}
但是,下一个问题是收集提交的值。为此,您需要在您通过
引用的backing
ui组件中实现
decode()
方法。或者,更好的方法是使用
渲染器创建自定义
ui组件
。在视图中接管
渲染器的工作是笨拙的

<myowntags:selectOneRadio>
  <f:selectItems  value="#{controller.items}"  />
</myowntags:selectOneRadio>
<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>