Bug with events in repeat control.
This has to be a bug with the repeat control: onclick events inside a repeat control are executed twice, and the second time the rowdata for another row is used.
You have to have more than a 100 rows for this to occur and you also have to set a rows (repeat limit) property of over 100. Then when you click on row number 11 the (server side) onclick event is triggered twice: once for row 11 but immediately followed by the same event using the data for row 101. If you have over 200 rows clicking row 21 will use row 201, etc. I tested with a view as datasource and also with a simple array.
I used a link control with an onclick event but while testing/debuggging I noticed this is also true for a label control, etc.
I noticed more strange results, like when you use a client-side event in the source code in the browser the events looks OK but behaves wrong: alert(‘11’) actually alerts ‘101’ and it also is triggered twice. Some rows are not triggered at all (row 101 for instance).
When I use the value property of the link control to trigger the same alert (javascript:alert(rowdata)) everything is OK. I use this for a workaround to set a session variable using clientside javascript instead of using the server-side onclick event (I use XSP.partialRefreshGet thanks to Jeremy Hodge: サッカー ユニフォーム 安い – xpagesblog.com | 安いジャージを買う。 21.99 という安いジャージ。 ファンに最高のコレクションを提供します。 安心してお買い物をしてください。)
Am I overlooking something or is this a bug? And maybe someone knows another workaround?
To test the server-side event you can create the following XPage:
<?xml version="1.0" encoding="UTF-8"?><xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>
<xp:repeat id="repeat1" rows="1000" var="indexItem">
<xp:this.value><![CDATA[#{javascript:var myArray = new Array();
for(i=0; i<1100; i++) {
myArray[i] = i.toString();
}
return myArray;}]]></xp:this.value>
<xp:link escape="true" id="linkInhoudsopgave1"
style="display:block;" value="#"
text="#{javascript:return indexItem;}">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print("indexItem = " + indexItem);}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
</xp:repeat>
</xp:view>
To test the clientside event you can create the following XPage:
<?xml version="1.0" encoding="UTF-8"?><xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>
<xp:repeat rows="200" var="indexItem" id="repeat1">
<xp:this.value><![CDATA[#{javascript:var myArray = new Array();
for(i=0; i<200; i++) {
myArray[i] = i.toString();
}
return myArray;}]]></xp:this.value>
<xp:link escape="true" style="display:block;" value="#"
text="#{javascript:return indexItem;}" id="link1">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[alert('#{javascript:indexItem;}');]]></xp:this.script>
</xp:eventHandler>
</xp:link>
</xp:repeat>
</xp:view>