2

I am trying to spread the radio buttons using tomahawk selectOneRadio. My id looks like this

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

I referred id after inspecting an element. But this is not working. Because for each iteration radio button id varies. How to refer an id in t:radio

Achaius
  • 5,904
  • 21
  • 65
  • 122
  • I don't do RichFaces/Seam, but doesn't just `for="models"` work? It would have worked without them. – BalusC Jan 22 '11 at 04:15

1 Answers1

1

The documentation for t:radio says:

The id of the referenced extended selectOneRadio component. This value is resolved to the particular component using the standard UIComponent.findComponent() searching algorithm.

I'm guessing a:repeat is a NamingContainer, so using "models" won't work. You can use the client identifier of the t:selectOneRadio component.

Something like this:

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

Caveats:

  1. This binds the component to the request scope map using the key "modelComponent"; you need to ensure this doesn't collide with something else
  2. Resolving modelComponent.clientId requires JSF 2.0 (JEE6) or above

See here for more details; working with older versions; etc.

McDowell
  • 107,573
  • 31
  • 204
  • 267