我有一个变量:
private ArrayList circleNameIdList;
在我的Action类中,它的值被填充.
我想在JSP的下拉列表中显示标签,当选择一个标签时,circleNameIdList中该特定标签的相应值将传递给服务器.
例如:如果标签:NewYork被选中,则它的对应id = 5,被发送到服务器.
我怎样才能做到这一点?
到目前为止,我在JSP中这样做:
但是,它显示不正确.
解决方法:
我看到你正在使用LableValueBean来填充并显示一个下拉列表.它最后用于显示对象列表的前bean.在Struts2中,您不再需要这样的帮助bean.您可以通过指定将包含所选选项的唯一值的键字段以及要显示为选项文本的值来显示对象列表.例如,如果你的对象
public class Circle {
private Long id;
//getter and setter here
private String name;
//getter and setter here
}
而你在动作类中
private List circleNameIdList;
//getter and setter here
/**
* Hold the selected value
*/
private Long circleId;
//getter and setter here
然后
list="circleNameIdList" listKey="id" listValue="name" headerKey="-1" headerValue="Select Circle"/>
可用于显示下拉列表.
标签:java,jsp,java-ee,struts2,ognl
来源: https://codeday.me/bug/20190624/1281111.html