I tried to iterate a map in jsf page. But after the map data modified, I found that always the last item was be removed on the page. The specific steps are as below:
Before clicking delete button:
After clicking delete button:
After refreshing page:
Before clicking delete button:
After clicking delete button:
After refreshing page:
jsf:
<h:panelGroup id="myPanel" layout="block">
<c:forEach var="entry" items="#{myController.myMap}">
<div class="col-md-2">
<h:outputText value="#{entry.key.date}" >
<f:convertDateTime pattern="dd/MM/YYYY" timeZone="GMT+8" />
</h:outputText>
</div>
<div class="col-md-1">
<h:commandLink>
<i id="delete-holiday" class="glyphicon glyphicon-trash"></i>
<f:ajax event="click" listener="#{myController.delete(entry.key)}" render="myPanel"></f:ajax>
</h:commandLink>
</div>
</c:forEach>
</h:panelGroup>
java code:
public void delete(Object date){
myMap.remove(date);
}