0

I believe JSF 2.2 does not iterate over Maps, so c:forEach has to be used.

I have a button that adds an object in a Map via Ajax. Afterwards, it renders the list of existing objects in the Map. I logged it, and the values are inserted well. The problem is that they are not updated/refreshed correctly in the xhtml page - well, sometimes they are, sometimes they are not.

<h:commandButton action="#{myController.addValue()}" type="submit" value="Add">
    <f:ajax execute="@this input1 input2" render="@form" /> 
</h:commandButton>
...
<h:panelGroup id="valuelist">

    <!-- This does not refresh properly -->
    <c:forEach items="#{myController.main.values}" var="entry">
        #{entry.value.name} / #{entry.value.description}
    </c:forEach>

    <!-- This does refresh properly -->
    <ui:repeat var="entry" value="#{myController.main.values.entrySet().toArray()}">
        #{entry.value.name} / #{entry.value.description}
    </ui:repeat>

</h:panelGroup>

I suppose it is something related to the JSF phases. I found a solution that uses ui:repeat, but it converts the Map to an array so I am not sure it is very efficient. How could I make the c:forEach refresh properly?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
user1156544
  • 1,725
  • 2
  • 25
  • 51

0 Answers0