primefaces selectOneMenu未排序

时间:2013-05-12 10:16:24

标签: java

我的页面中有一个selectonemenu,我从我的支持bean获取其内容。但是selectonemenu的内容没有排序。这是代码......

    <p:selectOneMenu id="Department" value="#{search.selectedDepartment}">  
            <f:selectItem itemLabel="Select Department" itemValue="" />  
            <f:selectItems value="#{search.departments}" />  

        </p:selectOneMenu> 

和我的豆......

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


}

和selectonemenu的内容分别不是department1,department2,department3,department4,department5。它没有排序。

2 个答案:

答案 0 :(得分:14)

它没有排序,因为HashMap没有可预测的迭代顺序。请改为LinkedHashMap

答案 1 :(得分:5)

LinkedHashMap 它的排序没有排序,即按顺序排列,但如果使用 TreeMap ,则按字母顺序排序