当页面上显示的textbox 是不能确定个数的时候,要想显示和更新数据就似乎有些不可能,但是通过HashMap,却可以实现这一点
在ActionForm中定义一个类型为HashMap的类变量
private HashMap investimatesubMap = new HashMap();

public Object getInvestimatesubMap(String key) ...{
return investimatesubMap.get(key);
}
public void setInvestimatesubMap(String key, Object value) ...{
this.investimatesubMap.put(key, value);
}

private Collection listInvestimatesub;
public void resetListInvestimatesub() {
Collection myInvestimatesub = new ArrayList();
Collection myKeys = investimatesubMap.keySet();
for (Iterator it = myKeys.iterator(); it.hasNext();) {
String key = (String) it.next();
String getKey = this.investimatesubMap.get(key).toString();
String[] properties = key.split("_");
String property = properties[0];
String vol = properties[1];
String id = properties[2];
InvestimatesubForm investimatesubForm = new InvestimatesubForm();
investimatesubForm.setEttprojid(this.ettprojid);
investimatesubForm.setVoltagegrade(vol);
investimatesubForm.setInvestestimateid(id);
investimatesubForm.setTranssubstninvest(getKey);
myInvestimatesub.add(investimatesubForm);
}
this.listInvestimatesub = myInvestimatesub;
}


public Collection getListInvestimatesub() {
if (this.listInvestimatesub == null) {
resetListInvestimatesub();
}
return listInvestimatesub;
}

public void setListInvestimatesub(Collection listInvestimatesub) {
this.listInvestimatesub = listInvestimatesub;
}
注意:变量一定要实例化,get方法的返回值一定是Object,set方法的value类型也一定是Object。
在进入jsp之前的Action中
InvestimatemainForm investimatemainForm = new InvestimatemainForm();
String key = "lineinvest_" + vol + "_" + id
investimatemainForm.setInvestimatesubMap("key", "testValue");
jsp中
map中的值一定不能加引号,错误示例:
可以用key值传递一些跟当前所填写的字段相关的信息,再在后台解析
在ActionForm中定义一个类型为HashMap的类变量
private HashMap investimatesubMap = new HashMap();
public Object getInvestimatesubMap(String key) ...{
return investimatesubMap.get(key);
}
public void setInvestimatesubMap(String key, Object value) ...{
this.investimatesubMap.put(key, value);
}
private Collection listInvestimatesub;
public void resetListInvestimatesub() {
Collection myInvestimatesub = new ArrayList();
Collection myKeys = investimatesubMap.keySet();
for (Iterator it = myKeys.iterator(); it.hasNext();) {
String key = (String) it.next();
String getKey = this.investimatesubMap.get(key).toString();
String[] properties = key.split("_");
String property = properties[0];
String vol = properties[1];
String id = properties[2];
InvestimatesubForm investimatesubForm = new InvestimatesubForm();
investimatesubForm.setEttprojid(this.ettprojid);
investimatesubForm.setVoltagegrade(vol);
investimatesubForm.setInvestestimateid(id);
investimatesubForm.setTranssubstninvest(getKey);
myInvestimatesub.add(investimatesubForm);
}
this.listInvestimatesub = myInvestimatesub;
}

public Collection getListInvestimatesub() {
if (this.listInvestimatesub == null) {
resetListInvestimatesub();
}
return listInvestimatesub;
}
public void setListInvestimatesub(Collection listInvestimatesub) {
this.listInvestimatesub = listInvestimatesub;
}注意:变量一定要实例化,get方法的返回值一定是Object,set方法的value类型也一定是Object。
在进入jsp之前的Action中
InvestimatemainForm investimatemainForm = new InvestimatemainForm();String key = "lineinvest_" + vol + "_" + id
investimatemainForm.setInvestimatesubMap("key", "testValue");jsp中
<html:text property="investimatesubMap(lineinvest_220_111)" maxlength="12" style="width: 100px;"/>
<html:text property="investimatesubMap(‘lineinvest_220_111’)" maxlength="12" style="width: 100px;"/>
可以用key值传递一些跟当前所填写的字段相关的信息,再在后台解析
本文介绍了一种利用HashMap在不确定数量的textbox中动态显示和更新数据的方法。通过实例展示了如何在ActionForm中定义和操作HashMap类型的变量,实现前端与后端的数据交互。
674

被折叠的 条评论
为什么被折叠?



