Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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">

Action class:

private List<String> departmentlist = new ArrayList<String>();

public String xyz()
{
    departmentlist.add("aaa");
    departmentlist.add("bbb");
    departmentlist.add("ccc");
    departmentlist.add("ddd");
    return "success";
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
654 views
Welcome To Ask or Share your Answers For Others

1 Answer

The error

"The requested list key 'departmentlist' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location] "

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...