I have an outer repeat control that gets it's collection as a hashmap(variable name is hmOuterCollection). Inside this repeat control there is another repeat control which gets it's collection as a hashmap (variable name is hmInnerCollection) as well. The inner repeat controls collection is based on the outer repeat entry's key. What happens is, the inner repeat control entries seems to overwrite the previous entries as I click through the outer repeat entries.
For example, consider the following
Barcelona (outer entry, clicked first)
Messi
Xavi
Puyol
Manchester United (outer entry, clicked second)
Rooney,
xxx
Real Madrid (outer entry, clicked third)
Ronaldo
Kaka
After I expanded all these soccer teams, I go back and click the player named Messi. It prints the name Ronaldo on the server console. If I click the name Xavi, it prints Kaka.
I just cant figure what's going on here. I tried the "repeatControls" and "removeRepeat" properties also. No luck. Is this a java hashmap caching or something wrong with the repeat control behavior.
Please let me know if anyone has any idea.
Here is the XPage source
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:script src="/xpTestCacheIssue.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xp:repeat id="repeat1" rows="30" value="#{javascript:getTeams()}"
var="entryTeam">
<xp:panel>
<xp:link escape="true"
text="#{javascript:entryTeam.getValue()}" id="lnkTeam">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="panelPlayers"
action="#{javascript:viewScope.teamID=entryTeam.getKey()}">
</xp:eventHandler>
</xp:link>
</xp:panel>
<xp:panel id="panelPlayers">
<xp:repeat id="repeat2" rows="30"
value="#{javascript:getPlayers(viewScope.teamID)}"
var="entryPlayer">
<xp:panel style="margin-left:20px;padding:10px">
<xp:link escape="true"
text="#{javascript:entryPlayer.getValue()}" id="lnkPlayer">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="selectedPlayer"
execMode="partial" execId="lnkPlayer">
<xp:this.action><![CDATA[#{javascript:viewScope.PlayerName=entryPlayer.getValue();}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
</xp:panel>
</xp:repeat>
</xp:panel>
</xp:repeat>
<xp:panel id="selectedPlayer" style="border:1px solid green;padding:20px;background-color:yellow;font-weight:bold">
<xp:text escape="true" id="computedField1"
value="#{javascript:viewScope.PlayerName}">
</xp:text>
</xp:panel>
Here is the java code that gets the hashmaps for these repeats. There is a SSJS function that calls the java methods.
public Map<String,String> getSoccerTeams() {
Map<String,String> hmTeams=new HashMap<String,String>();
try {
ViewEntryCollection vec=vwTeams.getAllEntries();
ViewEntry ve=vec.getFirstEntry();
while (ve!=null) {
hmTeams.put(ve.getUniversalID(), ve.getDocument().getItemValueString("TeamName"));
ve=vec.getNextEntry(ve);
}
} catch (Exception e) {
e.printStackTrace();
}
return hmTeams;
}
public Map<String,String> getPlayers(String idPlayer) {
HashMap<String,String> hmPlayers=new HashMap<String,String>();
try {
View vwPlayers=this.dbCur.getView("playersview");
DocumentCollection dc=vwPlayers.getAllDocumentsByKey(idPlayer, true);
Document doc=dc.getFirstDocument();
while (doc!=null) {
hmPlayers.put(doc.getUniversalID(), doc.getItemValueString("PlayerName"));
doc=dc.getNextDocument(doc);
}
} catch (Exception e) {
e.printStackTrace();
}
return hmPlayers;
}
Here is the SSJS code that calls the java methods.
function getTeams() {
var Teams=new LoadTeams();
var hmTeams=Teams.getSoccerTeams();
return hmTeams.entrySet();
}
function getPlayers(playerID) {
var Teams=new LoadTeams();
var hmPlayers=Teams.getPlayers(playerID);
return hmPlayers.entrySet();
}