0
votes

I want to change the rows of an repeat control dynamically, with a button.

code of the repeat:

<xp:repeat id="repeat1" rows="30" var="myrow">
            <xp:this.value><![CDATA[#{javascript:var myrows = new Array();
for (var i=0;i<viewScope.myrows;i++) {
myrows[i] = (i+1).toString()
};
myrows}]]></xp:this.value>
            <xc:ccrepeat FNameStatus="status_#{myrow}">
            </xc:ccrepeat>
        </xp:repeat>

a button increases the value of viewScope.myrows, and the array grows (like "1","2","3" - I check this in a computed field with the same code for the array), but my repeat controls only shows 1 row! Tried it with partial/full refresh and compute dynamically/on page load.

When I set viewScope.myrows intitially to a higher value, e.g. 5, the repeat displays 5 rows. So the problem seems to be the refresh.

Must be a simple error, but I get stuck. Thanks in advance for any help

Uwe

1
Can you post the code of your button?Sven Hasselbach

1 Answers

1
votes

Your mistake is when you calculate the <xp:this.value> of your repeat control. You have to use a scope/session/... to store your array so that the repatcontrol can access any changes on the array. Here a sample Code how it should work:

   <xp:repeat id="repeat2" rows="30" var="myrow">
        <xp:this.value><![CDATA[#{javascript://
            var list = viewScope.rowList;
            return (list && typeof list == "string")? new Array(list):list;}]]>
        </xp:this.value>
        <xp:text escape="true" id="computedField4"
                value="#{javascript:myrow.toString();}">
        </xp:text><br></br>
    </xp:repeat>
    <xp:button value="addRow" id="button2">
        <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="repeat2">
        <xp:this.action><![CDATA[#{javascript:var list = viewScope.rowList;
    if(list){
        if(typeof list == "string"){
            list = new Array(list);
        }
    }else{
        list = new Array();
    }
    list.push("newRow");
    viewScope.rowList = list;}]]>
            </xp:this.action>
        </xp:eventHandler>
    </xp:button>