struts2 - optiontransferselect - 将整数列表传递给操作
我在表单中有一个选项transferselect,但我不知道如何在我的操作中获取右侧列表中的选定项目。
我需要获取包含所有访问过的国家/地区 ID 的列表。 我在我的操作列表中尝试过(整数)countriesVisitedId; 但它返回 nullPointerException。 然后我尝试了 Integer id 但它返回 null。
这就是我所拥有的:
s:optiontransferselect
label="Select visited countries"
name="countriesNotVisitedId"
leftTitle="Not visited countries"
rightTitle="Visited Countries"
list="%{countriesNotVisited}"
listKey="id"
listValue="name"
headerKey="countryNotVisitedId"
headerValue="--- Please Select ---"
doubleName="countriesVisitedId"
doubleList="%{countriesVisited}"
doubleHeaderKey="countryVisitedId"
doubleHeaderValue="--- Please Select ---"
doubleListKey="id"
doubleListValue="name" />
如何在我的操作中获取包含所访问国家/地区的整数 ID 的列表?
I have an optiontransferselect in a form but i dont know how to get the selected items in the rightlist back in my action.
I need to get a list with all the visited countries' ids. i tried in my action List (Integer) countriesVisitedId; but it returns nullPointerException. then i tried Integer id but it returns null.
this is what i have:
s:optiontransferselect
label="Select visited countries"
name="countriesNotVisitedId"
leftTitle="Not visited countries"
rightTitle="Visited Countries"
list="%{countriesNotVisited}"
listKey="id"
listValue="name"
headerKey="countryNotVisitedId"
headerValue="--- Please Select ---"
doubleName="countriesVisitedId"
doubleList="%{countriesVisited}"
doubleHeaderKey="countryVisitedId"
doubleHeaderValue="--- Please Select ---"
doubleListKey="id"
doubleListValue="name" />
how can I get the list with the Integers ids of the visited countries in my action?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我用头撞墙,想知道我做错了什么。 这非常简单
doubleName="fields" 是返回的标记字段
public void setFields(String fields) { 这是您的操作类中需要的内容。
我没有意识到的是需要选择元素才能发回。 或者简单地在标头中使用 ajax with
I was banging my head on the wall wondering what I was doing wrong. It is pretty simple
doubleName="fields" is the tag field that is returned
public void setFields(String fields) { this is what needs to be in your action class.
The thing that I didn't realise is the elements need to be selected in order to be sent back. Or simple use ajax with in your header
这是我尝试过的,效果很好。
步骤1:JSP将国家从左侧选择到右侧。
第 2 步:Javascript 代码自动选择右侧的所有数据。
步骤 3:在提交时从 JSP 端调用此函数。
步骤4:在action中,使左右两侧对象名的getter和setter采用字符串而不是字符串数组。
现在,如果您尝试在操作中打印一个值,您将得到以下值:
Here's what I tried, it works fine.
Step 1: JSP to select the country from the left hand side into right hand.
Step 2: Javascript code to auto select all data from the right hand side.
Step 3: call this function on submit, from the JSP side.
Step 4: In the action, make the getters and setters of object names of the left and right sides take strings and not string arrays.
Now if you try to print a value in the action, you will get values:
在你的行动中:
In your action: