模仿webworkshowcase做个批量的修改,但是将list对象在jsp种iterator出来之后,在转到另一个action中这个list对象count总是为空。。什么原因?
我的xwork配置以及src如下
java 代码
- package?com.sms.webwork.action;??
- ??
- import?java.util.List;??
- import?java.util.Iterator;??
- import?java.util.ArrayList;??
- import?com.opensymphony.xwork.ActionContext;??
- import?com.opensymphony.xwork.ActionSupport;??
- import?com.sms.model.User;??
- import?com.sms.service.UserExistsException;??
- public?class?UserToolAction?extends?BaseAction{??
- //??private?static?final?long?serialVersionUID?=?6776558938712115191L;??
- ????String?username;??
- ????String?phoneNumber;??
- ????String?message;??
- ????List?users=new?ArrayList();??
- ????List?telephones=new?ArrayList();??
- ??????
- ????public?UserToolAction()??
- ????{??
- ??
- ????}??
- ??????
- ????public?String?getUsername()?{??
- ????????return?username;??
- ????}??
- ??
- ????public?void?setUsername(String?username)?{??
- ????????this.username?=?username;??
- ????}??
- ??????
- ????public?String?getPhoneNumber()?{??
- ????????return?phoneNumber;??
- ????}??
- ??
- ????public?void?setPhoneNumber(String?phoneNumber)?{??
- ????????this.phoneNumber?=?phoneNumber;??
- ????}??
- ??????
- ????public?String?doSubmit()?{??
- ??????????
- ????????User?newUser=new?User();??
- ????????newUser.setUsername(username);??
- ????????newUser.setPhoneNumber(phoneNumber);??
- ??????????
- ????????try??
- ????????{??
- ????????????userManager.saveUser(newUser);??
- ????????}??
- ????????catch(UserExistsException?ex)??
- ????????{??
- ????????????return?INPUT;??
- ??????????????
- ????????}??
- ????????return?SUCCESS;??
- ????}??
- ??????
- ????public?String?doEdit()??
- ????{??
- ????????Iterator?itr=users.iterator();??
- ????????while(itr.hasNext())??
- ????????{??
- ????????????try??
- ????????????{??
- ????????????????userManager.saveUser((User)itr.next());??
- ????????????}??
- ????????????catch(Exception?e)??
- ????????????{??
- ????????????????e.printStackTrace();??
- ????????????}??
- ??
- ????????}??
- ????????return?SUCCESS;??
- ????}??
- ????public?String?doList()??
- ????{??
- ????????//users=userManager.getUsers(new?User());??
- ????????users.addAll(userManager.getUsers(new?User()));??
- ????????//users.addAll(userManager.getUsers(new?User()));??
- ????????return?SUCCESS;??
- ??
- ????}??
- ????public?String?doListSubmit()??
- ????{??
- ????????return?SUCCESS;??
- ????}??
- ????/**?
- ?????*?A?default?implementation?that?does?nothing?an?returns?"success".?
- ?????*?
- ?????*?@return?{@link?#SUCCESS}?
- ?????*/??
- ????public?String?save()?throws?Exception?{??
- ??
- ????????for?(?Iterator?iter?=?users.iterator();?iter.hasNext();)?{??
- ????????????User?p?=?(User)?iter.next();??
- ????????????userManager.saveUser(p);??
- ????????}??
- ????????return?SUCCESS;??
- ????}??
- ????public?String?execute()?throws?Exception?{??
- ??????????
- //??????users=userManager.getUsers(new?User());??
- ????????users.addAll(userManager.getUsers(new?User()));??
- ????????//users.addAll(userManager.getUsers(new?User()));??
- ????????return?SUCCESS;??
- ????}??
- ??????
- ????public?List?getUsers()?{??
- ????????return?users;??
- ????}??
- ??
- ????public?void?setUsers(List?users)?{??
- ????????this.users?=?users;??
- ????}??
- ????public?List?getTelephones()?{??
- ????????return?telephones;??
- ????}??
- ??
- ????public?void?setTelephones(List?telephones)?{??
- ????????this.telephones?=?telephones;??
- ????}??
- }??
xml 代码
- <!---->>??
- ??
- <xwork>??
- ????<include?file="webwork-default.xml"/>??
- ??
- ????<package?name="default"?extends="webwork-default">??
- ??
- ????????<default-action-ref?name="home"?/>??
- ??
- ????????<action?name="home"?class="com.opensymphony.webwork.example.HomeAction">??
- ????????????<result>/WEB-INF/pages/home.jspresult>??
- ????????action>??
- ??
- ????????<!---->??
- ????????<action?name="addUser"?class="com.sms.webwork.action.UserAction">??
- ????????????<result>/WEB-INF/pages/home.jspresult>??
- ????????????<result?name="input">/WEB-INF/pages/adduser.jspresult>??
- ????????action>??
- ????????<action?name="addUserSubmit"?class="com.sms.webwork.action.UserAction"?method="doSubmit">??
- ????????????<result>/WEB-INF/pages/adduserSubmited.jspresult>??
- ????????????<result?name="input">/WEB-INF/pages/adduser.jspresult>??
- ????????action>??
- ?????????<!---->??
- ????????????<result?type="redirect">listUser.actionresult>??
- ????????action>??
- ??????????
- ????package>??
- ??????
- ????<package?name="ui-tags"?extends="webwork-default"?namespace="/tags/ui">??
- ????????<action?name="example"?class="com.opensymphony.webwork.showcase.UITagExample">??
- ????????????<result>example.jspresult>??
- ????????????<result?name="input">example.jspresult>??
- ????????action>??
- ????????<action?name="exampleSubmit"?class="com.opensymphony.webwork.showcase.UITagExample"?method="doSubmit">??
- ????????????<result>exampleSubmited.jspresult>??
- ????????????<result?name="input">example.jspresult>??
- ????????action>?????????????????
- ????package>??
- ??????
- ????<package?name="sms"?extends="webwork-default"?namespace="/sms">??
- ????????<action?name="sms"?class="com.sms.webwork.action.SmsAction"?method="doSearch">??
- ????????????<result>/WEB-INF/pages/sms.jspresult>??
- ????????????<result?name="input">/WEB-INF/pages/sms.jspresult>??
- ????????action>??
- ????????<action?name="smsSubmit"?class="com.sms.webwork.action.SmsAction"?method="doSubmit">??
- ????????????<result>/WEB-INF/pages/smsSubmited.jspresult>??
- ????????????<result?name="input">/WEB-INF/pages/sms.jspresult>??
- ????????action>????
- ????????????????
- ????package>??
- ??????
- xwork>??
java 代码
- <!---->??
- <!---->??
- ??
- ??
- ??????
- ??
- ??
- ??
- ???method="post"?namespace="/user"?theme="simple"?validate="false">??
- ????
??
??
ID User?Name Telephone ?? - ?????????????????????/>??
- ????????????????
- ????????
- ????????????
- ????????????
- ????????????
- ????????
- ???????????value="users">??
- ????????????
- ????????????????
- ???????????????? ??
- ?????????????????????name="users(%{id}).username"?value="%{username}"?theme="simple"?/>??
- ???????????????? ??
- ??
- ????????????
- ????????
- ????
- ??
- ????/>??
- ??
-
- ??
- ?????action="home"/>??
- ?
- ??
- ??
- ??
报错是
[sms] ERROR [http-8080-Processor23] ParametersInterceptor.setParameters(146) | Developer Notification (set webwork.devMode to false to disable this message):
Error setting expr 'users(6).username' with value '[Ljava.lang.String;@2ae278'
说明users里面根本没有对象。但是jsp上的list的确是users,java action中的list也是users,为什么到action还是没有呢?
1 楼
famoushz
2007-01-04
我把完整的包给传上来了,去掉了jar
2 楼
famoushz
2007-01-04
javaeye 的xml 显示有问题,还有jsp文件,还是大家看包里面的。
3 楼
famoushz
2007-01-04
问题已经解决
4 楼
iseeiconquer
2007-01-17
怎么解决的?
我也想知道,jsp页面里的整个集合的内容能否传到webwork action里面.
例如:<ww:select name="usertype" list="types"/>
我在刚开始进到相应页面list设置好后,再提交,如果处理这个提交的action方法里不重新设置list再result返回到那个jsp时就会报错:
could not be resolved as a collection/array/map/enumeration/iterator type
我也想知道,jsp页面里的整个集合的内容能否传到webwork action里面.
例如:<ww:select name="usertype" list="types"/>
我在刚开始进到相应页面list设置好后,再提交,如果处理这个提交的action方法里不重新设置list再result返回到那个jsp时就会报错:
could not be resolved as a collection/array/map/enumeration/iterator type
5 楼
dwangel
2007-01-17
list的子元素要初始化。
就是说users(6)是null,当然会出错
就是说users(6)是null,当然会出错