Reputation: 537
I am doing my project in struts2 framework. but i cant find a way to specify a dropdown list from a database.. is there a way.. pls help
Upvotes: 3
Views: 2564
Reputation: 23587
If you are talking about a drop down list in your JSP page than there is already a select Tag for that
<s:select name="mydrop_down" list="%{sports}" />
where list is a Iterable source to populate from. If the list is a Map (key, value), the Map key will become the option 'value' parameter and the Map value will become the option body.
All you need to create a List/Map/Array
in you action class and provide its getter and setter how the list will be picked form the ActionClass in jsp will be handled by the framewrok itself
public class MyAction extends ActionSuport{
private List<String> sports; //can be array or map etc
getters and setters for sports
public String execute() throws Exception{
sports = init the List and fill it
// can fill the list from database
return SUCCESS;
}
}
Upvotes: 4