簡體   English   中英

struts 2保存動態表對象

[英]struts 2 save dynamic table object

使用s2迭代器標記,我可以毫無問題地顯示表格。 我有兩個按鈕來添加行和使用Javascript刪除行。 下面是jsp頁面的片段

<s:iterator value="entities" status="outerStat">
  <tr>
    <TD><input type="checkbox" name="chk"/></TD>
    <TD>
      <table width="100%" cellspacing="4" cellpadding="0" border='0'>
        <s:textfield name="entities[%{#outerStat.index}].entityName" value="%{entityName}"/>
      </table>
    </TD>
    <TD>
      <table width="100%" cellspacing="4" cellpadding="0" border='0'>
        <s:select  list="entityTypes" value="%{entityType}"/>
      </table>
    </TD>
    <TD>
      <table width="100%" cellspacing="4" cellpadding="0" border='0'>
        <s:textarea  name="entities[%{#outerStat.index}].sqlStmt" cols="120" rows="4"  maxlength="4000" value="%{sqlStmt}"/>
      </table>
    </TD>
  </tr>
</s:iterator>

我的問題是,每當我單擊AddRow按鈕時,如何在服務器端為該行生成對象持有者? 服務器端如何知道在有效端添加了多少行?

正如你已經證明了, 你按一下按鈕,你就不會創建於各行的服務器端對象。 您正在創建表單-在提交表單之前,不會創建/持久化服務器端對象。 如果需要保證順序,則需要為“名稱”屬性的數組表示法保留一個JavaScript計數器。

可以通過單擊Ajax調用,創建對象並返回HTML以及該項目的ID或其他內容來在單擊時創建服務器端對象,但是不清楚您是否真正要這樣做。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM