0

Using tapestry 5.6.2

I want to do something like this

<t:loop t:source="orders" t:value="order">
    <t:RadioGroup name="shipping">

      <t:loop t:source="order.shippingOptions" value="shippingOption">
         <t:Radio value="shippingOption"/>
         <t:Label for="????">${shippingOption.description}<strong>${shippingOption.cost} 
              </strong></t:Label>
      </t:loop>
    </t:RadioGroup>
</t:loop>

The problem is that i can't anticipate which id is the Radio going to take and put it in the "for" parameter of the label

I tried making something like <t:radio id="${shippingOptionId}"...

and implement a "public String getShippingOptionId()" on the java side but that parameter is ignored

1 Answer 1

0

Tapestry will use a single instance of the Radio component to render the entire group. So the t:id will be the same for all items in the loop.

You should just be able to do

<t:RadioGroup name="shipping">
  <t:loop source="order.shippingOptions" value="shippingOption" encoder="myEncoder">
    <t:Radio t:id="shippingOption" value="shippingOption.value"/>
    <t:Label for="shippingOption">${shippingOption.description} ${shippingOption.cost}</t:Label>
  </t:loop>
</t:RadioGroup>

Note this requires a custom ValueEncoder

From the loop docs

In general, when using a non-volatile Loop in a Form, you should either provide a ValueEncoder with the encoder parameter or use a "value" type for which Tapestry is configured to provide a ValueEncoder automatically.

See the "Forms and Loops Example" in the Loop Docs

<t:loop source="items" value="item" encoder="encoder">
  <div class="line-item">
    <t:label for="quantity">${item.product.name}</t:label>
    <t:textfield t:id="quantity" value="item.quantity"/>
  </div>
</t:loop>

Note: You can't use ${...} notation for tapestry component attributes but you can use a binding prefix.

Instead of <t:foo value="${x.y.z}" />

You could do <t:foo value="prop:x.y.z" />

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.