【问题标题】:How to refer element id dynamically如何动态引用元素id
【发布时间】:2011-06-13 02:44:54
【问题描述】:

我正在尝试使用 tomahawk selectOneRadio 传播单选按钮。我的身份证是这样的

<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

【问题讨论】:

  • 我不做 RichFaces/Seam,但不只是 for="models" 工作吗?没有他们也可以。

标签: jsf richfaces seam myfaces tomahawk


【解决方案1】:

documentation for t:radio 说:

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

我猜a:repeatNamingContainer,所以使用"models" 是行不通的。您可以使用t:selectOneRadio 组件的client identifier

类似这样的:

<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) 或更高版本

详情请见here;使用旧版本;等等

【讨论】:

    猜你喜欢
    • 2018-09-24
    • 1970-01-01
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-29
    • 2018-02-23
    • 2022-07-06
    相关资源
    最近更新 更多