0

I think I want something impossible, but I'll give it a try.

I have the following code:

<xp:repeat id="repeat1" rows="30" var="rowData" repeatControls="false" indexVar="index">
<xp:this.value>
    <![CDATA[#{javascript:var value1 = docDocument.getItemValue("DocInternNume");
    var toStr1 = value1.toString().replace("[","").replace("]","").split(",");

    var value2 = docDocument.getItemValue("DocIntern");
    var toStr2 = value2.toString().replace("[","").replace("]","").split(",");

    var ar = new Array(2);
    for(var x =0; x<ar.length;x++)
    {
       ar[x] = new Array(toStr1.length)
       for(var y=0;y<toStr1.length;y++){
           if(x==0){
              ar[x][y] = toStr1[y];
           }
           if(x==1){
               ar[x][y] = toStr2[y];
           }
       }
    }

    return ar;}]]></xp:this.value>
    <xp:link escape="true" id="link2" text="#{javascript:rowData;}"
        value="#{javascript:rowData;}">
    </xp:link>
    <xp:br></xp:br>
</xp:repeat>

Code explanation:

A repeat control which takes as value 2 fields which have:

  • 1st has a String array containing some Names;
  • 2nd has a String array containing the docID;

    After that, I am saving those field values in a multidimensional array, length of 2 which I return as the repeat value.

    Why do I return a multidimensional array in the repeat:

    In the repeat as you can see in the above code I have a link which label I want to take the value of the 1st field (the Names) and the URL I want to take the value of the 2nd field (the docID).

    Why? because I want to give the user the capability to select some documents in a parent document and after, in a repeat to show the links to the child documents.

    Question: is there a way to return a multidimensional array within a repeat and then give to the label for eg: rowData[0] and to the URL the rowData[1] value? Or is there another way I can achieve this?

    As far as I could do the repeat only returns an array.

    3 Answers 3

    1

    Could you not use nested repeat controls? An outer repeat and in inner repeat?

    For instance have an outer repeat of documents... then an inner repeat of a multi value field for each document?

    the inner repeat uses the varName of the outer

    So if you had RepeatOuter - varName = outerData

    you then could do: repeatInner - varName = innerData BUT when you build the inner repeat... you have whatever is in "outerData" available for that lookup / use

    Sign up to request clarification or add additional context in comments.

    Comments

    0

    If it were me, I would pass the repeat the first array, as usual. Set the var for the repeat to something like 'rowdata'.

    For the second array, I would load that into the viewScope (or sessionScope if you need it for a longer time).

    When building the repeat, I would use the indexVar of rowData to grab the appropriate member of the second array.

    The experts may come up with a more advanced Java data structure but I'm not as familiar with those structures yet.

    Comments

    0

    If you want to show two properties of a list of objects, if one is unique (and in this case the URL will be) a Map is the best option. Here is an example you can use http://mardou.dyndns.org/Privat/osnippets.nsf/snippet.xsp?documentId=EB17DF835CCE2F5CC1257C1C0074C823 You can use map.entrySet() or map.keySet() as the source.

    If you want more properties, that's the time to start creating Objects based on a class. After all, that's basically what a ViewEntryCollection or DocumentCollection is.

    Maps may seem a foreign concept, but they're something all XPages developers are familiar with: the scopes (viewScope, requestScope, sessionScope etc) are all just Maps, with a key and value.

    Comments

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.