环路
问题描述:
我在用下面的代码问题提交背景:环路
<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">
点击任一按钮将只触发事件onRemoveLocation
与上下文2504658
。
我猜第二个提交组件是重写第一个注册的事件处理程序,所以他们最终都调用第二个组件事件处理程序。
我曾尝试将clientId
设置为独特的东西,但没有帮助。
我需要删除按钮来提交相同的表单,因为用户可以更新一个元素的名称并删除第二个在同一个操作。
建议感激,p。
(挂毯5.1.0.5)
答
当使用Submit
一个循环中与上下文,你还需要设置defer="false"
,以避免此行为:
<t:submit t:event="RemoveLocation" t:value="remove ${location.hashCode()}"
t:context="${location.hashCode()}" t:defer="false" />
从docs:
推迟:如果为true(默认值),那么组件发送的任何通知将被推迟到th表单提交的结束(这通常是可取的)。一般来说,除了Submit组件在Loop中渲染时,这可以保留为默认值,在这种情况下,应将defer绑定为false(否则,事件上下文始终是Loop的最终值)。
谢谢henning。 – pstanton 2011-05-16 21:10:27