Struts2 多行数据提交问题。

evangoe 2011-06-16 04:55:37
我在页面上使用js做了一个表格动态增加的功能:

function addrow(){
root = document.all.dtable;
var allRows = root.getElementsByTagName('tr');
var allCells = allRows[0].getElementsByTagName('td');
var newRow = root.insertRow();

var newCell0 = newRow.insertCell();
var newCell1 = newRow.insertCell();
var newCell2 = newRow.insertCell();
var newCell3 = newRow.insertCell();
var newCell4 = newRow.insertCell();
var newCell5 = newRow.insertCell();
var newCell6 = newRow.insertCell();
var newCell7 = newRow.insertCell();
var newCell8 = newRow.insertCell();
var newCell9 = newRow.insertCell();
var newCell10 = newRow.insertCell();
var newCell11 = newRow.insertCell();
var newCell12 = newRow.insertCell();
var newCell13 = newRow.insertCell();


newCell0.innerHTML = "<input name='list[%{#ele.index}].item_code' type='text' value='' style='width:45px' />";
newCell1.innerHTML = "<input name='list[%{#ele.index}].item_name' type=text value='' style='width:75px'>";
newCell2.innerHTML = "<input name='list[%{#ele.index}].item_dw' type=text value='' style='width:35px'>";
newCell3.innerHTML = "<input name='list[%{#ele.index}].item_spec' type=text value='' style='width:65px'>";
newCell4.innerHTML = "<input name='list[%{#ele.index}].item_dhs' type=text value='' style='width:45px'>";
newCell5.innerHTML = "<input name='list[%{#ele.index}].item_dhxs' type=text value='' style='width:45px'>";
newCell6.innerHTML = "<input name='list[%{#ele.index}].item_sfs' type=text value='' style='width:45px'>";
newCell7.innerHTML = "<input name='list[%{#ele.index}].itme_sfxs' type=text value='' style='width:45px'>";
newCell8.innerHTML = "<input name='list[%{#ele.index}].item_sfcx' type=text value='' style='width:25px' readonly>";
newCell9.innerHTML = "<input name='list[%{#ele.index}].item_fhdj' type=text value='' style='width:45px'>";
newCell10.innerHTML = "<input name='list[%{#ele.index}].item_cxdj' type=text value='' style='width:45px'>";
newCell11.innerHTML = "<input name='list[%{#ele.index}].item_je' type=text value='' style='width:45px'>";
newCell12.innerHTML = "<input name='list[%{#ele.index}].item_cxhje' type=text value='' style='width:45px'>";
newCell13.innerHTML = "<a href='javascript:deleterow();'>删除</a>";

}


这个JS对应的表格是:

<table width="100%" border="0" align="center" class="datalist" id=dtable>
<tr align="center">
<th class="tableHeader">物资编号</th>
<th class="tableHeader">物资名称</th>
<th class="tableHeader">物资单位</th>
<th class="tableHeader">物资规格</th>
<th class="tableHeader">商品订货数量</th>
<th class="tableHeader">商品订货箱数</th>
<th class="tableHeader">发货数量</th>
<th class="tableHeader">发货箱数</th>
<th class="tableHeader">是否促销</th>
<th class="tableHeader">发货单价</th>
<th class="tableHeader">促销单价</th>
<th class="tableHeader">商品金额</th>
<th class="tableHeader">促销后金额</th>
<th width=10% class="tableHeader">操作</th>
</tr>
<s:iterator value="#request.list" id="ele">
<tr align="center" bgcolor=#FFFFFF>
<td><input name='list[%{#ele.index}].item_code' type='text' value='<s:property value="#ele.item_code" />' style='width:45px' /> </td>
<td><input name='list[%{#ele.index}].item_name' type=text value='<s:property value="#ele.item_name" />' style='width:75px'></td>
<td><input name='list[%{#ele.index}].item_dw' type=text value='<s:property value="#ele.item_dw" />' style='width:35px'></td>
<td><input name='list[%{#ele.index}].item_spec' type=text value='<s:property value="#ele.item_spec" />' style='width:65px'></td>
<td><input name='list[%{#ele.index}].item_dhs' type=text value='<s:property value="#ele.item_dhs" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].item_dhxs' type=text value='<s:property value="#ele.item_dhxs" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].item_sfs' type=text value='<s:property value="#ele.item_sfs" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].itme_sfxs' type=text value='<s:property value="#ele.itme_sfxs" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].item_sfcx' type=text value='<s:property value="#ele.item_sfcx" />' style='width:25px' readonly></td>
<td><input name='list[%{#ele.index}].item_fhdj' type=text value='<s:property value="#ele.item_fhdj" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].item_cxdj' type=text value='<s:property value="#ele.item_cxdj" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].item_je' type=text value='<s:property value="#ele.item_je" />' style='width:45px'></td>
<td><input name='list[%{#ele.index}].item_cxhje' type=text value='<s:property value="#ele.item_cxhje" />' style='width:45px'></td>
<td></td>
</tr>
</s:iterator>
</table>



就是用户可以点击添加行按钮实现动态添加一行,然后点击保存的时候,将行数据提交到后台进行保存或者更新。
可是现在发现后台获得数据为空,我也添加内容为:
Element_list=org.indigotin.outdepot.OutdepotDetail
CreateIfNull_list=true
的代码,后台部分代码为:
action:
private String list;


public String getList() {
return list;
}

public void setList(String list) {
this.list = list;
}

总而言之,就是想实现在用户动态添加表格后,提交到后台进行保存,现问题是,后台获得不到前台提交的数据库。

望高手解决
...全文
594 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
catslee 2011-06-17
  • 打赏
  • 举报
回复
其实还可以定义各个属性为对象数组,也可以
evangoe 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 evangoe 的回复:]

唉,粗心大意的~居然把list定义为String类型,要是获得了,才怪了!
[/Quote]

是啊,可以了!呵呵~
Fly_m 2011-06-16
  • 打赏
  • 举报
回复
你的list内的元素的类型为string,肯定 不行,应该是表示你每一行数据的那个类型。
强长黑粗硬 2011-06-16
  • 打赏
  • 举报
回复
你这样提交就成功了?

struts2不是要写配置文件的吗?
evangoe 2011-06-16
  • 打赏
  • 举报
回复
唉,粗心大意的~居然把list定义为String类型,要是获得了,才怪了!
evangoe 2011-06-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ypb137154098 的回复:]

在action中定义一个:private List list; 的属性,并提供get和set方法!就可以了吧!
[/Quote]

我已经做了


action:
private String list;


public String getList() {
return list;
}

public void setList(String list) {
this.list = list;
}
ypb137154098 2011-06-16
  • 打赏
  • 举报
回复
在action中定义一个:private List list; 的属性,并提供get和set方法!就可以了吧!

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧