I've two pieces of code, one that work and one that doesn't. I'm accessing accessing different objects in from a list in different selectOneMenu
. So if my list is of size 4 then I have 4 selectOneMenu
. There is a spinner
above the selectOneMenu
's to notify how many of them I want.
I don't understand why the first one using varstatus
to access a list works and the second one which use the var doesn't. A Map
is a custom entity btw.
Works :
<p:spinner value="#{matchCreation.numbreOfmaps}" min="1" max="7">
<f:ajax event="change" render="mapsGroup" execute="mapsGroup"/>
</p:spinner>
<!-- maps start -->
<h:panelGroup id="mapsGroup">
<table>
<ui:repeat var="mapPlayed" value="#{matchCreation.playedMaps}" varStatus="status">
<tr><td>
<p:selectOneMenu value="#{matchCreation.playedMaps[status.index]}">
<f:selectItems value="#{matchCreation.mapList}" var="map" itemValue="#{map}" itemLabel="#{map.name}"/>
<f:converter binding="#{mapConverter}"/>
</p:selectOneMenu>
</td></tr>
</ui:repeat>
</table>
</h:panelGroup>
Does NOT work :
<p:spinner value="#{matchCreation.numbreOfmaps}" min="1" max="7">
<f:ajax event="change" render="mapsGroup" execute="mapsGroup"/>
</p:spinner>
<!-- maps start -->
<h:panelGroup id="mapsGroup">
<table>
<ui:repeat var="mapPlayed" value="#{matchCreation.playedMaps}">
<tr><td>
<p:selectOneMenu value="#{mapPlayed}">
<f:selectItems value="#{matchCreation.mapList}" var="map" itemValue="#{map}" itemLabel="#{map.name}"/>
<f:converter binding="#{mapConverter}"/>
</p:selectOneMenu>
</td></tr>
</ui:repeat>
</table>
</h:panelGroup>
In this one the list will contain the number of map specified but they will all be equal to mapList.get(0)
.
java:
private List<Map> mapList; // initiated in post construct.
private List<Map> playedMaps;
private int numbreOfmaps = 1;
public List<Map> getPlayedMaps() {
// I know this is not advised but I didn't really think of another way.
// It's not heavy work anyway.
while (playedMaps.size() > numbreOfmaps) {
playedMaps.remove(playedMaps.size() - 1);
}
while (playedMaps.size() < numbreOfmaps) {
playedMaps.add(mapList.get(0));
}
return playedMaps;
}