I have a selectonemenu in my page and i get its contents from my backing bean. But contents of selectonemenu is not sorted.Here is the code...
<p:selectOneMenu id="Department" value="#{search.selectedDepartment}">
<f:selectItem itemLabel="Select Department" itemValue="" />
<f:selectItems value="#{search.departments}" />
</p:selectOneMenu>
and my bean...
public class SearchBean implements Serializable {
private Map<String, Map<String, String>> courseData = new HashMap<String, Map<String, String>>();
private Map<String, String> departments = new HashMap<String, String>();
private String selectedDepartment;
departments.put("department1",
"department1");
departments.put("department2",
"department2");
departments.put("department3", "department3");
departments.put("department4", "department4");
departments.put("department5", "department5");
//getters setters...
}
and contents of selectonemenu is not department1,department2,department3,department4,department5 respectively.It is not sorted.
It's not sorted because HashMap
doesn't have a predictable iteration order. Try LinkedHashMap
instead.
with LinkedHashMap it is ordered not sorted i.e you get it in order which you put the items, but if you use TreeMap then it is sorteted alphabetically
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With