通过s:iterator传了一个list到jsp,那么逆过程怎么写,就是让这个s:iterator中的信息传回list,新的list也行,原文如下。项目经理不让在JSP里写JAVA代码。<s:iterator value="kczyList" id="ml" status="mlstatic">
资源分数:
<input
id="fs_<s:property value="#ml.ZYDFB_ID"/>"
value="<s:property value="#ml.ZYFS"/>"/>
资源分数:
<input
id="fs_<s:property value="#ml.ZYDFB_ID"/>"
value="<s:property value="#ml.ZYFS"/>"/>
action中定义一个List<YourObject> list生成set方法
前台的input name属性使用list[${mlstatic.index}].ZYFS或者list[<s:property value='#mlstatic.index'/>].ZYFS这样action就能接收了。
关键要弄明白struts2的ognl。
这里${mlstatic.index}就是为了取得你的下标,转换成数字就会变成list[0].ZYFS,list[1].ZYFS
最后问下,jsp能做一个map<String,String>然后返回action吗,不用OGNL的话
jsp的话你要自己去实现
<s:iterator value="kczyList" id="ml" status="mlstatic">
资源分数:
<input name="kczyList[s:property value="#mlstatic.index"/>].ZYFS"
id="fs_<s:property value="#ml.ZYDFB_ID"/>"
value="<s:property value="#ml.ZYFS"/>"/>
资源分数:
<input name="kczyList[<s:property value="#mlstatic.index"/>].ZYFS"
id="fs_<s:property value="#ml.ZYDFB_ID"/>"
value="<s:property value="#ml.ZYFS"/>"/>
这种写法action里得不到
我改成了name=“list[<s:property value='#mlstatic.ORDERS'/>].ZYFS"
list[${mlstatic.index}].ZYFS
和action里取得到取不到还有很远,你先打开页面源代码,看看是不是变成了
name=“list[0].ZYFS"
name=“list[1].ZYFS"
name=“list[2].ZYFS"
如果变了不可能取不到,没变当然取不到。
是变了的,但是取不到值,到action里list还是空的……我没用ognl
你用不用ognl是你能决定的,struts能不能解析ognl不是你能决定的你自己把对象名改了,那你后台有这个加了泛型的list变量吗?有get/set吗。
这里有个struts list传参例子,希望对你有帮助。
get/set肯定有啊。你是说一定要用ognl吗
根据你的变量名改变,还有我也说了如果你这里的<s:property value="#mlstatic.index"/>没用就换成${mlstatic.index}
怎么使用OGNL呢,需要哪些配置文件?
private List kczyList= new ArrayList();
public String zyPy() throws Exception{
if(kczyService.pyzy(zyfs, yhzyb_id,kczyList)){
sign = "updateSuccess";
}else{
sign = "updateFail";
}
return "pyzyview";
}
public List getKczyList() {
return kczyList;
}
public void setKczyList(List kczyList) {
this.kczyList = kczyList;
}JSP代码<s:iterator value="kczyList" id="ml" status="mlstatic">
<input type="text" class="asArea" id="tmfs<%=j++%>" size="2"
name="kczyList[${mlstatic.index}].FS" onkeyup="setfz();" style="width:4em;margin:0 2px;" />
</s:iterator> 虽然在网页源文件中,下标已经修改了
<input type="text" class="asArea" id="tmfs1" size="2"
name="kczyList[0].DF" onkeyup="setfz();" style="width:4em;margin:0 2px;" />但是进入action中仍然没有值啊
换成name=“kczyList[<s:property value='#mlstatic.index'/>].ZYFS"
也不行,我看有哪里没写对吗……
资源分数:
<input
id="fs_<s:property value="#ml.ZYDFB_ID"/>"
value="<s:property value="#ml.ZYFS"/>" name="kczyList2[mlstatic.index].ZYFS"/>这样我上个项目用过,应该可以实现吧!
<input type="text" size='1'
name="list[<s:property value="#v.index"/>].rubM"
id="list[<s:property value="#v.index"/>].rubM"
maxlength="100" value="<s:property value="rubM"/>" />
</td>
<td>
<input type="text" size='1'
name="list[<s:property value="#v.index"/>].rubR"
id="list[<s:property value="#v.index"/>].rubR"
maxlength="100" value="<s:property value="rubR"/>" />
</td>
</s:iterator>
<s:iterator value="kczyList" status="mlstatic">
资源分数:
<input
id="fs_<s:property value="#ml.ZYDFB_ID"/>"
value="<s:property value="#ml.ZYFS"/>"
name="kczyList2[<s:property value=#mlstatic.index/>].ZYFS" />
2.jquery将参数获取,然后通过点击事件传入,根据你的需求是不是发送ajax请求就看你是否需要了。