目前我正在处理一个包含2个按钮的表单。单击1按钮我将获得html字段块,如下所示。

`

<table width="100%">
    <tbody><tr>

      <td class="style4" width="12%" align="center">CODE<span class="style3"> </span></td>
      <td width="18%"><input name="c_code[]" value="" id="c_code__" class="box_border" style="width: 120px;" type="text"></td>
      <td class="style3" width="15%" align="right">Price</td>
      <td width="7%"><input name="c_price[]" value="" id="c_price__" class="box_border" style="width: 40px;" type="text"></td>
      <td class="style3" width="4%" align="right">Qty</td>
      <td width="7%"><input name="c_qty[]" value="" id="c_qty__" class="box_border" style="width: 40px;" type="text"></td>
      <td class="style3" width="9%" align="right">On Sale </td>

      <td width="3%"><input name="c_onsale[]" id="c_onsale__" value="" type="radio">    
<label for="c_onsale"></label>
</td>
      <td class="style3" width="10%" align="center">Exposition</td>
      <td width="15%"><input name="c_exposition[]" size="15" value="" id="c_exposition__" class="box_border" type="text"></td>
    </tr>
  </tbody></table>

`

现在每次用户点击按钮时,上面给出的整个块将使用ajax方法调用包含在html表单中。

  1. 现在我的问题是如何在struts2动作类中将所有元素的值作为数组获取。 或者如何为这些数组编写setter和getter方法。
  2. 有没有更好的方法以其他方式执行上述操作,这使我的工作更轻松?

    1. 如何为像这样的数组字段编写struts2验证文件?
    2. 任何人都可以帮我解决这个问题。

      感谢。

有帮助吗?

解决方案

好的,如果您可以使用数组中的索引为每次迭代重命名字段,那么它们将被命名为c_name [0],c_name [1]等...然后您可以在您的数组中定义一个数组动作类和映射将毫无问题地完成。 至于验证,我建议对您的操作进行服务器端验证。

此致

其他提示

在服务器端使用List而不是数组,struts会自动将新部分(UI上的新元素块)映射到它。

如果您将其定义为数组,则每次都无法初始化新部分,因为大小无法动态增加

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top