开发者

submit context in loop

I'm having a problem with the follo开发者_运维百科wing code:

<t:form t:id="locationsForm" t:zone="myZone">
    <t:loop t:source="locations" t:value="location" t:encoder="locationEncoder">
        <t:textfield t:value="location.name" />
        <t:submit t:event="RemoveLocation" t:value="remove ${location.hashCode()}" t:context="${location.hashCode()}" />
    </t:loop>
    <t:submit t:value="save" />
</t:form>

Say I end up with the following buttons:

<input type="submit" name="button" id="button" value="remove 12339020">
<input type="submit" name="button" id="button" value="remove 2504658">

Clicking on either button will only ever trigger the event onRemoveLocation with the context 2504658.

I'm guessing the second submit component is overriding the event handler registered by the first, so they both end up calling the second components event handler.

I have tried setting the clientId to something unique but that did not help.

I need the remove buttons to submit the same form since the user may update the name of one element and remove the second in the same operation.

Advice appreciated, p.

(Tapestry 5.1.0.5)


When using Submit inside a loop with a context, you'll also need to set defer="false" to avoid this behavior:

<t:submit t:event="RemoveLocation" t:value="remove ${location.hashCode()}"
    t:context="${location.hashCode()}" t:defer="false" />

From the docs:

defer: If true (the default), then any notification sent by the component will be deferred until the end of the form submission (this is usually desirable). In general, this can be left as the default except when the Submit component is rendering inside a Loop, in which case defer should be bound to false (otherwise, the event context will always be the final value of the Loop).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜