简体   繁体   English

struts 2保存动态表对象

[英]struts 2 save dynamic table object

With s2 iterator tag, I can display table without problem. 使用s2迭代器标记,我可以毫无问题地显示表格。 and I have two button to add row and delete row with Javascript. 我有两个按钮来添加行和使用Javascript删除行。 Below is the snippet of jsp page 下面是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>

My question is , everytime I click AddRow button, how can I generate a object holder for that row in server side? 我的问题是,每当我单击AddRow按钮时,如何在服务器端为该行生成对象持有者? how does the server side know that how many rows are added in cient side? 服务器端如何知道在有效端添加了多少行?

As you've shown it, you wouldn't create a server-side object for each row as you click the button. 正如你已经证明了, 你按一下按钮,你就不会创建于各行的服务器端对象。 You're creating a form--the server side object wouldn't be created/persisted until the form is submitted. 您正在创建表单-在提交表单之前,不会创建/持久化服务器端对象。 If you need to guarantee order, you'd need to keep a JavaScript counter for the "name" attribute's array notation. 如果需要保证顺序,则需要为“名称”属性的数组表示法保留一个JavaScript计数器。

You could create a server-side object on the click by making an Ajax call, creating the object, and returning the HTML along with the item's ID or whatever, but it's not clear from your question if that's what you actually want to do. 可以通过单击Ajax调用,创建对象并返回HTML以及该项目的ID或其他内容来在单击时创建服务器端对象,但是不清楚您是否真正要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM