Struts 2选择带有数组列表值的标签 [英] Struts 2 select tag with values of a array list
问题描述
我正在开发一个简单的 struts 应用程序.在我的 JSP 中,我有一个下拉列表框(使用 s:select
标记).我需要在操作类中使用数组列表值填充值.我怎样才能做到这一点?structs.xml
文件中需要哪些更改才能完成此操作?
I am developing a simple struts application. In my JSP I have a dropdown list box (using s:select
tag). I need to fill the values with a arraylist values in the action class. How can I do that? what changes needed in the structs.xml
file for complete this?
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";
}
推荐答案
错误
"请求的列表键 'departmentlist' 无法解析为集合/数组/映射/枚举/迭代器类型.示例:人或people.{name} - [未知位置] "
"The requested list key 'departmentlist' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location] "
表示 select
标记无法将 departmentlist
解析为集合.它是一个 OGNL 表达式,它试图在值堆栈中找到 departmentlist
,如果它没有找到或包含 null
引用 select
标记会抱怨.当您呈现 select
标记时,请确保列表位于值堆栈中并已初始化.请参阅此处的示例.
means that the select
tag is not able to resolve departmentlist
as a collection. It is an OGNL expression which is trying to find the departmentlist
in the value stack and if it not found or contains a null
reference the select
tag will complain. When you render the select
tag make sure the list is in the value stack and is initialized. See the example here.
这篇关于Struts 2选择带有数组列表值的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!