I have bean "MyBean", which has property HashMap - "map" which values type is MyClass. I want to show some properties of map in jsf using ui:repeat. But these code:
<ui:repeat var="var" value="#{mybean.map}" >
<tr>
<td> <h:outputText value="#{var.value.property1}"></h:outputText> </td>
<td><h:outputText value="#{var.value.property2}"></h:outputText></td>
</tr>
</ui:repeat>
But this code didn't show anything. Though when I try to show hashmap values in jsp this way, it was succesfull. Where I am wrong? And how fix that?
From the documentation for the
repeat
value attribute:So, var is set as your
HashMap
and EL tries to look up the key"value"
on it. You will need to expose your entry set as aList
.That's indeed a major pita. The
<c:forEach>
supportedMap
for long. Apart from supplying another getter as suggested by McDowell, you could also workaround this by a custom EL function.where the EL function look like this
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 thenSet#toArray()
.