2012-01-09 60 views
0

我遇到了一個Struts 1表單的問題,它包含一個邏輯:iterate負責創建行,每個行都有一個輸入按鈕。 問題出現時,我打任何的提交按鈕,動態數據不能正常公佈和形式不具有這些值,這裏有一個例子:Struts 1 - 行提交

<html:form action="/myAction" styleClass="centeredForm" style="display:inline" > 
    <td class="formLabel">City</td> 
    <td class="formControl"> 
    <bean:define id="cities" name="myForm" 
       property="cities" type="java.util.Collection"/> 
    <html:select styleClass="dashSelect" property="city"> 
     <html:option value="">All Cities</html:option> 
     <html:options collection="cities" 
        property="id" labelProperty="value"/> 
    </html:select> 
    </td> 

    ... Other elements ... 

    <logic:iterate id="myObject" name="myForm" property="myObjects" indexId="index" type="com.test.MyObject"> 
     <% String rowClass = index.intValue() % 2 == 0 ? "even-row" : "odd-row"; %> 
    <tr class="<%=rowClass%>"> 
     <td class="result-cell"><bean:write name="myObject" property="id" />&nbsp;</td> 
     <td class="result-cell"><bean:write name="myObject" property="name" />&nbsp;</td> 
     <td class="result-cell"> 
     <html:select styleClass="dashSelect" name="myObject" property="status"> 
      <html:option value="F">Disabled</html:option> 
      <html:option value="T">Enabled</html:option> 
     </html:select> 
     </td> 

     <td> 
     <html:submit/> 
     </td> 

「城市」部分和在邏輯之外休息:迭代,在「myForm」上出現得很好,但「myObject」不是。我甚至嘗試用JavaScript函數提交,但無法正常工作。 目前,我所擁有的(HTML:提交我留下作爲參考)導致POST包含一堆「狀態」參數和我前面提到的正確值。

任何人都可以對此有所瞭解嗎?

讓我知道你是否需要更多信息。

非常感謝!

+0

不確定你的意思;你沒有使用'indexed'標籤(參見[這裏](http://struts.apache.org/1.2.7/faqs/indexedprops.html))或者嵌套標籤,也沒有手動建立索引屬性名稱 - I儘管如此,還不完全清楚哪些部分無法正常工作。 (看起來在一些標籤/ bean中也有很多額外的工作;你是否考慮過使用JSP EL或者至少是EL Struts標籤,如果你使用的是過時的容器?) – 2012-01-09 21:51:01

+0

問題是,當我點擊提交時,表單沒有填充「myObject」,這是我通過邏輯:iterate創建的每一行的信息。 我將在此期間看看索引標籤。 – LdSe 2012-01-09 22:19:14

回答

0

代替使用一個單一的形式,我剛使用的形式的邏輯內:迭代,加入索引到相應的屬性和使用的Javascript函數來獲得其餘部分。

謝謝!

0

邏輯迭代:試試這樣做它可能會幫助你。

<logic:iterate name="myForm" property="myObjects" id="myObjects" indexId="true"> 
    <tr> 
    <td class="result-cell"><bean:write name="myObjects" property="id" />&nbsp;</td> 
     <td class="result-cell"><bean:write name="myObjects" property="name"/>&nbsp;</td> 
     <td> 
     <html:submit/> 
     </td>  
    </tr> 
</logic:iterate> 
+0

Hello subodh, 不幸的是,bean:write沒有值或索引屬性。 :( 您是否有意使用另一個? 非常感謝您的迴應! – LdSe 2012-01-10 14:06:25

+0

哦!!然後會發生什麼,如果您沒有使用值和索引,屬性它顯示任何錯誤或輸出是什麼?我的更新答案試圖做到這一點,如果有任何問題讓我知道。 – subodh 2012-01-11 05:03:57