When I use f:selectItems to display items in a Map I cannot display the value of the Map item, only the key. f:selectItems does not use the itemLabel at all. When I use a List instead things work.
The following does make use of the itemLabel to display the "description" of an item in a List:
<h:selectOneMenu>
<f:selectItems value="#{testBB.testList}" var="s"
itemLabel="TEST #{s.description}" itemValue="#{TEST s.name}" />
</h:
selectOneMenu>
The following attempt to display the value of an item in a Map does not work. It displays the item's key, but not using the itemLabel attribute, as can be discerned by that lack of output of the "TEST" text.
<rich:select>
<f:selectItems value="#{testBB.testMap}" var="s"
itemLabel="TEST #{s.value}" itemValue="TEST #{s.key}" />
</rich:select>
The simple backing bean used follows:
public class TestBB {
private Map<String, String> testMap;
private List<TestItem> testList;
public TestBB() {
testMap = new HashMap<String, String>();
testMap.put("1_key", "Item One");
testMap.put("2_key", "Item Two");
testMap.put("3_key", "Item Three");
testList = new ArrayList<TestItem>();
testList.add( new TestItem("name_1", "description_1") );
testList.add( new TestItem("name_2", "description_2") );
testList.add( new TestItem("name_3", "description_3") );
}
public Map<String, String> getTestMap() {
return testMap;
}
public List<TestItem> getTestList() {
return testList;
}
}
So, any ideas on how to make this work, that is, how to effectively use a Map with selectItems?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…