循环提交上下文

发布于 2024-11-07 14:17:53 字数 1006 浏览 0 评论 0原文

我在使用以下代码时遇到问题:

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

假设我最终得到以下按钮:

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

单击任一按钮都只会触发上下文 2504658 的事件 onRemoveLocation

我猜测第二个提交组件正在覆盖第一个提交组件注册的事件处理程序,因此它们最终都会调用第二个组件的事件处理程序。

我尝试将 clientId 设置为唯一的值,但这没有帮助。

我需要删除按钮来提交相同的表单,因为用户可以在同一操作中更新一个元素的名称并删除第二个元素。

感谢建议,p。

(挂毯5.1.0.5)

I'm having a problem with the following 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音栖息无 2024-11-14 14:17:53

在具有上下文的循环内使用 Submit 时,您还需要设置 defer="false" 以避免此行为:

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

文档

延迟:如果为 true(默认值),则组件发送的任何通知都将推迟到表单提交结束(这通常是可取的)。一般来说,可以将其保留为默认值,除非 Submit 组件在 Loop 内渲染,在这种情况下 defer 应绑定为 false(否则,事件上下文将始终是 Loop 的最终值)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文