Using JSF 1.2 and JSP....
Is it possible to iterate over a Map whose values contain Collections?
I have a Map that looks li
JSF doesn't have any component which can iterate over a Map. Only the JSTL <c:forEach> can iterate over a Map
. Each iteration gives you a Map.Entry back which in turn has getKey()
and getValue()
methods. You can in turn use a <h:dataTable> to iterate over the map value.
<c:forEach items="#{bean.map}" var="entry">
<p>Key: <h:outputText value="#{entry.key}" /></p>
<h:dataTable value="#{entry.value}" var="foo">
<h:column><h:outputText value="#{foo.prop1}" /></h:column>
<h:column><h:outputText value="#{foo.prop2}" /></h:column>
<h:column><h:outputText value="#{foo.prop3}" /></h:column>
</h:dataTable>
</c:forEach>
Update this works only when you're using JSTL 1.2. This fails in JSTL 1.1 because #{}
is not recognized in JSTL 1.1 tags and hence you're forced to use ${}
, but this in turn fails in the nested JSF components because they accept #{}
only. You'd basically need to fall back to "plain" JSP/HTML in that entire piece of code, or, better, grab Tomahawk's <t:dataList>
.