2010-04-16 38 views
0
<form jwcid="@Form" listener="listener:updateStaff"> 


<select jwcid="[email protected]" multiple="ognl:false" validators="validators:required" onchange="this.form.submit()" listener="listener:updateStaff"> 
       <span jwcid="@For" source="ognl:hrStaff" value="ognl:currentHrStaff" index="ognl:currentHrStaffIndex"> 
        <option class="text11" jwcid="@Option" selected="ognl:hrStaffSelection[currentHrStaffIndex]" label="ognl:currentHrStaff"/> 
       </span> 
      </select> 


</form> 

當selectbox上的onchange時,這個表單將被提交,我的pageValidate()將被upadteStaff()方法調用。我想知道,當這樣的提交被解僱,可以onchange =''通過一個標誌('selectboxisfired'字符串),我能夠捕獲pagevalidate()'selectboxisfired'內?這將允許我的pagevalidate內部的邏輯指示是由selectbox觸發的。onchange force頁面提交

回答

1
onchange="window.submitTrigger=this; this.form.submit();" 

然後你就可以讀取你的驗證程序的window.submitTrigger變量去尋找哪些元素觸發提交,例如

/* somewhere in pagevalidate() routine */ 
/* note here that I am assuming the html id of the selectbox is "staffselect" 
    -> I'm not familiar with Tapestry so simply had to make the assumption 
     that this is the correct id - if not, change the string you're searching 
     for accordingly */ 
if (window.submitTrigger.id = "staffselect") { 
    //do something here 
} 

值得注意的是,是,我認爲這是不好的風格中使用的onchange這種方式,但是不理解Tapestry,我只是給你最簡單的改變,已經存在的,我認爲會工作...

+0

on pagevalidate(),如何獲得這個window.submittrigger? – cometta 2010-04-17 08:47:59

+0

聲明'window.submitTrigger = this;'創建一個附屬於窗口對象的屬性,名爲'submitTrigger'(它可以是任何你喜歡的名字,submitTrigger就是一個例子),並將其設置爲'this'(其中'this '是當前的元素,我將編輯我的答案,以舉例說明在pagevalidate()中可能會做什麼。 – Graza 2010-04-19 10:06:26