我有一个变量:
private ArrayList<LabelValueBean> circleNameIdList;
在我里面Action
填充其值的类。
我想在 JSP 的下拉列表中显示标签,当选择一个标签时,该特定标签的对应值circleNameIdList
要传递到服务器。
例如:如果标签:NewYork
被选中那么它是对应的id = 5
,被发送到服务器。
我怎样才能实现这个目标?
到目前为止,我在 JSP 中是这样做的:
<s:select list="#session.circleNameIdList" label="Select Circle:" name="circleNameIdList" id="circleNameIdList"></s:select>
但是,它的显示不正确。
我看到你正在使用LableValueBean
填充并显示下拉菜单。它以前是一个 bean,最后用于显示对象列表。在 Struts2 中,您不再需要这样的辅助 bean。您可以通过指定一个关键字段来显示对象列表,该关键字段将保存所选选项的唯一值以及要显示为选项文本的值。例如,如果你的对象
public class Circle {
private Long id;
//getter and setter here
private String name;
//getter and setter here
}
你在动作课上
private List<Circle> circleNameIdList;
//getter and setter here
/**
* Hold the selected value
*/
private Long circleId;
//getter and setter here
then
<s:select id="circleNameIdListID" label="Circle:" name="circleId"
list="circleNameIdList" listKey="id" listValue="name" headerKey="-1" headerValue="Select Circle"/>
可用于显示下拉菜单。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)