action中得到<s:optiontransferselect/>标签中的内容
struts2的 action中得到<s:optiontransferselect/>标签中的内容关键字: struts2 action <s:optiontransferselect/>
最近用到struts2 <s:optiontransferselect/>标签,要求在action中获取<s:optiontransferselect/>标签中的内容
出现这个问题后,发现确实很难实现,所以就Google了下,但获取答案却不理想
但研究struts2的demo后,发现他们可以正常获取的,所以就研究了下,发现问题其实很简单:
在此,借用下Google时,搜索到的一个问题
Html代码
<s:form action="TestTagLib"> <s:optiontransferselect label="optiontransferselect Test" labelposition="top" list="{'thomas1','ada','lothar'}" name="leftList" addToLeftLabel="向左移动" addToRightLabel="向右移动" addAllToLeftLabel="left" addAllToRightLabel="right" doubleName="rightList"doubleList="{'Expert One-on-One J2EE Design and Development', 'JavaScript: TDefinGuide'}" /> <s:submitvalue="login"/> </s:form> <s:form action="TestTagLib">&nbsp; &nbsp; &nbsp; &nbsp;<s:optiontransferselect &nbsp; &nbsp; label="optiontransferselect Test"&nbsp; &nbsp; labelposition="top"&nbsp; &nbsp; list="{'thomas1','ada','lothar'}"&nbsp; &nbsp; name="leftList"&nbsp; &nbsp; addToLeftLabel="向左移动"&nbsp; &nbsp; addToRightLabel="向右移动"&nbsp; &nbsp; addAllToLeftLabel="left"&nbsp; &nbsp; addAllToRightLabel="right"&nbsp; &nbsp; doubleName="rightList"&nbsp;doubleList="{'Expert One-on-One J2EE Design and Development', 'JavaScript: TDefinGuide'}"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; />&nbsp; &nbsp; &nbsp;<s:submit&nbsp; value="login"/>&nbsp; &nbsp; </s:form> 然后提交到TestTagLibAction中,在action中设置了setter(),getter()方法,关键代码如下: private List leftList;private List rightList; public List getLeftList() {return leftList;} public void setLeftList(List leftList) {this.leftList = leftList;} public List getRightList() {return rightList;} public void setRightList(List rightList) {this.rightList = rightList;} 为什么在execute()方法中得不到 rightList的值? 其中rightList对应前面jsp页面中 <s:optiontransferselect/>的doublename="rightList"标签,代码如下: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;List list1=getRightList();for(int i=0;i <list1.size();i++){System.out.println(list1.get(i).toString());}
提交后,就能在后台得到rightList里面的值了。
如果没有这段Js代码,后台是得不到值的,这是Struts2 <s:optiontransferselect/>本身的bug.
呵呵,首先感谢这位兄弟的回答,这样做应该是可以的(ps:我没有测试)
但这不是struts2的bug
问题出在html中的代码上
用firebug监控表单的提交的时候,会获取到一个dojo错误,其实问题很简单:
缺失
Html代码
1. <s:head/>
<s:head/>
这个标签
因在struts2中集成了dojo,所以不导入dojo肯定会出现问题了
呵呵,就这么简单.
非常感谢上面引述的那位兄弟的回答
以上问题的来源地:http://topic.csdn.net/u/20080127/15/4539cf2e-7309-4de8-9289-fa0fe02496b5.html
页:
[1]