Xpages toolbar with nested repeat controls - @DbLookup unable to access var value of parent repeat control

StackOverflow https://stackoverflow.com/questions/23467647

  •  15-07-2023
  •  | 
  •  

Question

I have a toolbar that should allow users to select the make of a car. The makes are pulled through using the var request scope variable in the repeat control. However, when I try and access the corresponding values using @DbLookup, it fails to return anything. Below is the code snippet:

<xe:toolbar id="toolbar1" showButtonLabels="true">
  <xe:this.treeNodes>
    <xe:pageTreeNode label="Make">
      <xe:this.children>
        <xe:repeatTreeNode indexVar="index"
        loaded="true" var="varValue">
          <xe:this.value>
            <![CDATA[#{javascript:@Unique(@DbColumn("", "parts list", 1))}]]>
          </xe:this.value>
          <xe:this.children>
            <xe:pageTreeNode
            label="#{javascript:varValue}">
              <xe:this.children>
                <xe:repeatTreeNode
                indexVar="index1" loaded="true" var="varValue1">
                  <xe:this.value>
                    <![CDATA[#{javascript:@Unique(@DbLookup("", "parts list", requestScope.varValue, 2))}]]>
                  </xe:this.value>
                  <xe:this.children>
                    <xe:pageTreeNode
                    label="#{javascript:requestScope.varValue1}">
                    </xe:pageTreeNode>
                  </xe:this.children>
                </xe:repeatTreeNode>
              </xe:this.children>
            </xe:pageTreeNode>
          </xe:this.children>
        </xe:repeatTreeNode>
      </xe:this.children>
    </xe:pageTreeNode>
    <xe:pageTreeNode label="Vehicle">
    </xe:pageTreeNode>
  </xe:this.treeNodes>
  <xp:eventHandler event="onItemClick" submit="true"
  refreshMode="partial" refreshId="toolbar1">
  </xp:eventHandler>
</xe:toolbar>

Can anyone tell me where I'm going wrong? Or how can I gain access to the varValue variable on the selected item in the first list?

An example of what I want is under the toolbar tab in the following link: http://www.xpages.jp/demos/xpagesext.nsf/Core_Outline.xsp Also, I am new to xpages. Thanks guys.

Was it helpful?

Solution

The toolbar renders into the XPages component tree as a single component. So it is quite hard to get hands on any values. When you render repeat controls in a different context, things work quite nicely. For the toolbar you could use an ugly hack like the one below, or you render your specific toolbar in a manual control using repeats. I got this sample to work:

    <?xml version="1.0" encoding="UTF-8"?>
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
        <xp:this.afterPageLoad><![CDATA[#{javascript:var result = new java.util.LinkedList();
    var allMakes = @Unique(@DbColumn("", "parts list", 1));
    for (var makeIndex in allMakes) {
       var curModelName = allMakes[makeIndex];
       var someModels = @Unique(@DbLookup("", "parts list", curModelName, 2));
       if (someModels != null) {
          result.offer(someModels);
          result.offer(someModels);
       }
    }
    viewScope.ModelsAndMakes = result;   }]]></xp:this.afterPageLoad>
        <xe:toolbar id="toolbar1" showButtonLabels="true">
            <xe:this.treeNodes>
                <xe:pageTreeNode label="Make">
                    <xe:this.children>
                        <xe:repeatTreeNode indexVar="indexMakes" loaded="true"
                            var="varMakes">

                            <xe:this.children>
                                <xe:pageTreeNode label="#{varMakes}">
                                    <xe:this.children>
                                        <xe:repeatTreeNode indexVar="indexModel"
                                            loaded="true" var="varModel">

                                            <xe:this.children>
                                                <xe:pageTreeNode label="#{varModel}">
                                                </xe:pageTreeNode>
                                            </xe:this.children>
                                            <xe:this.value><![CDATA[#{javascript:if (view.isRenderingPhase()) {
        return viewScope.ModelsAndMakes.poll();
    };}]]></xe:this.value>
                                        </xe:repeatTreeNode>
                                        <xe:basicLeafNode label="Fixed ende after">
                                        </xe:basicLeafNode>
                                    </xe:this.children>
                                </xe:pageTreeNode>
                            </xe:this.children>
                            <xe:this.value><![CDATA[#{javascript:@Unique(@DbColumn("", "parts list", 1))}]]></xe:this.value>
                        </xe:repeatTreeNode>
                    </xe:this.children>
                </xe:pageTreeNode>

            </xe:this.treeNodes>
            <xp:eventHandler event="onItemClick" submit="true"
                refreshMode="partial" refreshId="toolbar1">
            </xp:eventHandler>
        </xe:toolbar>
        <ol>
            <xp:repeat id="repeat1" rows="30" var="outerList" indexVar="outerIndex">
                <xp:this.value><![CDATA[#{javascript:@Unique(@DbColumn("", "parts list", 1))}]]></xp:this.value>
                <li>
                    <xp:text escape="true" id="computedField1" tagName="h3"
                        value="#{outerList}">
                    </xp:text>
                    <ol>
                        <xp:repeat id="repeat2" rows="30" var="innerList">
                            <xe:this.value>
                            <![CDATA[#{javascript:@Unique(@DbLookup("", "parts list", outerList, 2))}]]>
                            </xe:this.value>
                            <li>
                                <xp:text escape="true" id="computedField2" value="#{innerList}">
                                </xp:text>
                            </li>
                        </xp:repeat>
                    </ol>
                </li>
            </xp:repeat>
        </ol>
    </xp:view>

The double entries in the result.offer is necessary since the lifecyle polls twice. As I said: ugly hack Let us know how it goes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top