環路

2011-05-16 51 views
3

我在用下面的代碼問題提交背景:環路

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

回答

6

當使用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的最終值)。

+0

謝謝henning。 – pstanton 2011-05-16 21:10:27