I’m using struts select tag in my forms.I use a Hash map to populate it. When I load the page a method in the action class will call another class which uses hibernate to fetch data and returns a Map. Then the method in the action class will get that Map object and use to populate the select tag. This works properly but even if I get the list sorted from the database (I checked using a console print) the slect tag doesn’t display it sorted. I think this happens either when I copy the valus from database class Map object to action class Map object or when the select tag is populating. Any solutions?
This is how I fill the Map in my action class
private Map<String, String> serialList;
//in the method
serialList=new DropdownFiller().getSealNoForItemsAndLocation();
//the getSealNoForItemsAndLocation() returns a Map
I’ve used Maps where order is important in struts2 without issue. But the Map has to provide a predictable iteration order such as a LinkedHashMap, a regular Hashmap does not provide predictable iteration… a TreeMap could also work, there are a couple other implementations too.
http://download.oracle.com/javase/6/docs/api/java/util/LinkedHashMap.html