2

我正在尝试使用 tomahawk selectOneRadio 传播单选按钮。我的 id 看起来像这样

<rich:dataTable id="carTable" value="#{cars}" var="car">
    <rich:column>
        <s:decorate id="types" template="/layout/display-text.xhtml">
            <t:selectOneRadio id="models" value="#{car.model}" layout="spread">
                <f:selectItems value="#{models}" />
            </t:selectOneRadio>
            <h:panelGrid columns="2">
                <a:repeat value="#{models}" rowKeyVar="index">
                    <t:radio for="car:carTable:0:types:models" index="#{index}"></t:radio>
                </a:repeat>
            </h:panelGrid>  -->
        </s:decorate>
    </rich:column> 
</rich:dataTable>

我在检查一个元素后引用了 id 。但这不起作用。因为对于每次迭代,单选按钮 id 都会有所不同。如何在 t:radio 中引用 id

4

1 回答 1

1

t:radio的文档说:

引用的扩展 selectOneRadio 组件的 id。使用标准UIComponent.findComponent()搜索算法将此值解析为特定组件。

我猜a:repeat是 a NamingContainer,所以使用是"models"行不通的。您可以使用组件的客户端标识符t:selectOneRadio

像这样的东西:

<t:selectOneRadio id="models" value="#{car.model}" layout="spread"
   binding="#{requestScope.modelComponent}">
  <f:selectItems value="#{models}" />
</t:selectOneRadio>
<h:panelGrid columns="2">
  <a:repeat value="#{models}" rowKeyVar="index">
    <t:radio for="#{requestScope.modelComponent.clientId}" index="#{index}" />
  </a:repeat>
</h:panelGrid>

注意事项:

  1. 这使用键“modelComponent”将组件绑定到请求范围映射;你需要确保这不会与其他东西发生冲突
  2. 解析modelComponent.clientId需要JSF 2.0(JEE6)或更高版本

请参阅此处了解更多详情;使用旧版本;等等

于 2011-01-23T13:20:44.363 回答