How to display hashmap in JSF using selectonemenu?

I have a Java hash map with a list of groups:

private HashMap<String, String> listGroups = new HashMap<>();

The question is, how can I display values ​​from hashmap in selectonemenu?

+5
source share
1 answer

<f:selectItems> already supports cards.

<f:selectItems value="#{bean.listGroups}" />

The card key becomes the option label, and the card value becomes the parameter value.

However, you probably want to use LinkedHashMapinstead HashMapif it is important to display the map entries in the input order or TreeMapif you want to automatically sort them by card key.

see also

+20
source

All Articles