我正在开发一个简单的struts应用程序。在我的JSP中,我有一个下拉列表框(使用s:select
标签)。我需要在action类中用arraylist值填充值。我怎样才能做到这一点? structs.xml
文件需要进行哪些更改才能完成此操作?
JSP:
<s:select name="department" label="" list="departmentlist" headerKey="-1" headerValue="Select Department">
行动类:
private List<String> departmentlist = new ArrayList<String>();
public String xyz()
{
departmentlist.add("aaa");
departmentlist.add("bbb");
departmentlist.add("ccc");
departmentlist.add("ddd");
return "success";
}
答案 0 :(得分:2)
错误
“请求的列表密钥'departmentlist'无法解析为 collection / array / map / enumeration / iterator类型。例如:人或 人。{name} - [unknown location]“
表示select
代码无法将departmentlist
解析为集合。这是一个OGNL表达式,它试图在值堆栈中找到departmentlist
,如果找不到或包含null
引用,则select
标记会抱怨。渲染select
标记时,请确保列表位于值堆栈中并初始化。请参阅示例here。
答案 1 :(得分:0)
Try to add get and set method for our field departmentlist,in your class Exple : in your class controller put this method for your field departmentlist :
public List<String> getDepartmentlist(){
return this.departmentlist();
}
public void setDepartmentlist(List<String> departmentlist){
return this.departmentlist = departmentlist;
}