小日本是这样处理LIST表单更新/插入的

在JSP中 每个字段对应一个数组。
<input name = "masterName[0]" .../> <input name = "familyId[0]" .../>
<input name = "masterName[1]" .../> <input name = "familyId[1]" .../>
<input name = "masterName[2]" .../> <input name = "familyId[2]" .../>
在ActionForm中
定义一个 List list;
没有与数组名对应的变量
只有对应的方法
private void setMasterName(String[] masterName) {
Map map = new HashMap();
for (int i = 0; i < masterName.length(); i++) {
map.put("masterName[i]", masterName[i]);
list.add(map);
}
}
好象写错了,明天去看看小日本的代码

package jp.co.nec.cw.portal.form;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jp.co.nec.cw.portal.common.form.ZPBaseForm;
public class YU011191Form extends ZPBaseForm {
/** List */
List <Map<String, Object>> siireList;

/**
* 从List中取出所有tenpoCode值放入数组
*/
public String[] getTenpoCode() {
String[] tenpoCode = new String[siireList.size()];
for(int i=0;i<siireList.size();i++){
Map m = (Map)siireList.get(i);
tenpoCode[i] = "";
if (m.get("tenpoCode") != null) {
tenpoCode[i] = m.get("tenpoCode").toString();
}
}

return tenpoCode;
}

/**
* 从List中取出指定"记录"中的tenpoCode值
*/
public String getTenpoCode(int index) {
Map m = (Map)siireList.get(index);
String tenpoCode = "";
if (m.get("tenpoCode") != null) {
tenpoCode = m.get("tenpoCode").toString();
}

return tenpoCode;
}

/**
* 将页面对应的数组tenpoCode中的所有值放入List
*/
public void setTenpoCode(String[] tenpoCode) {
Map<String, Object> m = null;
for(int i=0;i<tenpoCode.length;i++){
if (i < siireList.size()) {
//此时取出来的Map也许已经包含其它"字段"
m = (Map)siireList.get(i);
}
if (m == null) {
m = new HashMap<String, Object>();
}
//将tenpoCode的值添加到map中
m.put("tenpoCode", tenpoCode[i]);
if (i < siireList.size()) {
//替换对应"记录"
siireList.set(i,m);
} else {
siireList.add(m);
}
m = null;
}
}

/**
* 将页面对应的指定"记录"的tenpoCode的值放入List
*/
public void setTenpoCode(int index, String tenpoCode) {
Map<String, Object> m = null;
if (index < siireList.size()) {
m = (Map)siireList.get(index);
}
if (m == null) {
m = new HashMap<String, Object> ();
}
m.put("tenpoCode", tenpoCode);
if (index < siireList.size()) {
siireList.set(index,m);
} else {
siireList.add(m);
}
}

}

JSP部分:

<%
YU011191Form yu011191 = (YU011191Form)session.getAttribute("YU011191Form");
List list = yu011191.getSiireList();
Map map = new HashMap();
String[] strTenpoCode = null;
if (list != null) {
strTenpoCode = yu011191.getTenpoCode();
}
/* 行の色 */
String line = new String();
for (int i = 0; i < list.size(); i++) {
if (i % 2 == 0) {
/* 偶数 */
line = "c-line1";
} else {
/* 奇数 */
line = "c-line2";
}
%>
<tr class="<%= line %>">
<td align="left" nowrap="nowrap">
<%= (strTenpoCode[i] != null && strTenpoCode[i].trim().length() != 0) ?
CmnUtil.paddingZero(strTenpoCode[i], 3) : " " %>
</td>
<input type="hidden" name="<%= "tenpoCode[" + i + "]" %>" value="<%= strTenpoCode[i] %>">
</tr>
<%
}
%>

至于当页面数据(数组)提交时,对应的Servlet Action (控制层) 怎么就知道调用ActionForm里的
public void setTenpoCode(String[] tenpoCode) 方法呢?
还不清楚,再去研究研究,希望小日本没有把基类代码给藏起来.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值