I have seen a couple other examples on SO discussing some weird workarounds but none seem to work and they were all addressed at versions prior to JSF 2. So, it it possible to simply output the keys of a map? I’ve tried ui:repeat and c:forEach like below with no luck:
<c:forEach items="${myBean.myMap.keySet}" var="var">
<h:outputText value="#{var}"/>
</c:forEach>
From your code:
This is not going to work. This requires a
getKeySet()method on theMapinterface, but there is none.If your environment supports EL 2.2 (Servlet 3.0 containers like Tomcat 7, Glassfish 3, etc), then you should invoke the
keySet()method directly instead of calling it as a property:Or if your environment doesn’t support EL 2.2 yet, then you should iterate over the map itself directly which gives a
Map.Entryinstance on every iteration which in turn has agetKey()method, so this should do as well:None of above works with
<ui:repeat>as it doesn’t supportMapnorSet. It supportsListand array only. The difference between<c:forEach>and<ui:repeat>is by the way that the<c:forEach>generates multiple JSF components during view build time and that the<ui:repeat>creates a single JSF component which generates its HTML output multiple times during view render time.