That's indeed a major pita. The <c:forEach>
supported Map
for long. Apart from supplying another getter as suggested by McDowell, you could also workaround this by a custom EL function.
<ui:repeat value="#{util:toList(bean.map)}" var="entry">
#{entry.key} = #{entry.value} <br/>
</ui:repeat>
where the EL function look like this
public static List<Map.Entry<?, ?>> toList(Map<?, ?> map) {
return = map != null ? new ArrayList<Map.Entry<?,?>>(map.entrySet()) : null;
}
Or, if you're on EL 2.2 already (provided by Servlet 3.0 compatible containers such as Glassfish 3, Tomcat 7, etc), then just use Map#entrySet()
and then Set#toArray()
.
<ui:repeat value="#{bean.map.entrySet().toArray()}" var="entry">
#{entry.key} = #{entry.value} <br/>
</ui:repeat>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…