JSF 1.2 - iterate over a Map that contains Collections

前端 未结 1 892
花落未央
花落未央 2021-01-18 05:48

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

相关标签:
1条回答
  • 2021-01-18 06:37

    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>.

    0 讨论(0)
提交回复
热议问题