如何使用selectonemenu在JSF中显示哈希图? [英] How to display hashmap in JSF using selectonemenu?

查看:97
本文介绍了如何使用selectonemenu在JSF中显示哈希图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java哈希图,其中包含一个组列表:

I have a Java hashmap with a a list of a groups:

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

问题是如何将哈希表中的值显示到selectone菜单中?

The question is how I can display the values from the hashmap into the selectonemenu?

推荐答案

<f:selectItems>已支持地图.

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

地图键成为选项标签,地图值成为选项值.

The map key becomes the option label and the map value becomes the option value.

也就是说,如果按插入顺序显示地图条目很重要,则可能要使用LinkedHashMap而不是HashMap;如果要按地图关键字自动对它们进行排序,则可能要使用TreeMap.

That said, you probably want to use LinkedHashMap instead of HashMap if displaying the map entries in insertion order is important, or TreeMap if you want to automatically sort them by map key.

这篇关于如何使用selectonemenu在JSF中显示哈希图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆