3
votes

I have been learning Xpages programming. We are currently using domino 8.5.2. I am gaining familiarity with the display/input controls and I have had some success using them to display information from backend domino documents, views, scoped variables that are not an array. What I have not been able to discover is how to display the elements of a scoped variable array that is created dynamically.
For instance: I create an array with a number of elements. I can print the elements to the domino log with the following code:

for (var i=0; i<array.length; i++) {
    print(array[i])
}

What do I use to display the individual elements on webpage? I apologize if the answer if obvious. I did find one posting about displaying a 2 dimensional array - but was unable to interpret the answer.
Thanks for any guidance. ---Lisa&

2
Lisa, I removed the JavaScript tag to not get wrong answers that focus on csjs. Also, upgrade Domini to 9.0.1 or at least the latest 8.5.3. Your XPages experience will be much better :-)Per Henrik Lausten
We are planning to go to 9.0.1 as soon as we can.user4920643

2 Answers

4
votes

Use a repeat control and show elements within repeat in a computed field:

<xp:this.beforePageLoad><![CDATA[#{javascript:
    var myTest = []; 
    for (var i=0; i<9; i++) {
        myTest[i] = i; 
    } 
    viewScope.myTest = myTest;
}]]></xp:this.beforePageLoad>
<xp:repeat
    id="repeat1"
    rows="30"
    var="row"
    value="#{viewScope.myTest}">
    <xp:text
        escape="true"
        id="computedField1"
        value="#{javascript:row.toString()}">
    </xp:text>
    <br />
</xp:repeat>

The array is in viewScope.myTest in this example.

1
votes

A very quick way to display the content of an array is using the join function. No repeat required but the display is limited.

<xp:this.beforePageLoad><![CDATA[#{javascript:
    var arrTest= ["a","b","c","d"];
    viewScope.myTest = myTest;
}]]></xp:this.beforePageLoad>

    <xp:text id="testField"
        value="#{javascript:viewScope.arrTest.join('; ')">
    </xp:text>

This shows

a; b; c; d

You could add HTML around it to pretty it up, and set the display type of the text field to be HTML whcih gives you the opton to join with HTML eg

value="#{javascript:viewScope.arrTest.join('<br>')"

Not as complete a solution as a repeat control, but good for quick things.