Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 using Map in select tag

Tags:

struts2

You can easily use a List in struts2 select tag, but is there a way to use Map in tag?? If it is possible please provide a sample code...

thanx !

like image 992
Chathuranga Withana Avatar asked May 22 '10 07:05

Chathuranga Withana


2 Answers

In my action class

public class MyAction extends ActionSupport {
   private Map<String, String> map;

   public String execute() throws Exception {
       map = new HashMap<String, String>();
       map.put("abc", "abc");
       map.put("xyz", "xyz");
       return SUCCESS;
   }
}

For the jsp mapped to success, use some thing like this

<s:select list = "map" name = "name" label = "Name" headerKey="" headerValue = "Enter Value"/>
like image 93
Kartik Avatar answered Nov 20 '22 20:11

Kartik


It depends on what are you trying to do. Lacking details, I can only point you to the docs : the list attribute of the select tag is an ...

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.

Below in the same doc there is an example with a (literal, inline) map (Months).

like image 42
leonbloy Avatar answered Nov 20 '22 22:11

leonbloy