Question

I have created a toolBar with a number of basicLeafNodes. In some JS in the style property I would like to get the label value for the basicLeafNode. I tried this.label but that throws and error. If I could get the label value then I could write a very generalized block of code that would be the same for every leaf in the toolBar. Which would be easier to maintain and extend. This is a long way from a show stopper but it would be neat,

Was it helpful?

Solution

You can't do that, because this represents the toolbar object, not the leaf node (it's all one giant object).

However, you might use repeatTreeNode and some Javascript magic (or preferably a managed bean), all values can be calculated and management could be easier for the future.

    <xe:toolbar id="toolbar1">
        <xe:this.treeNodes>
            <xe:repeatTreeNode var="item">
                <xe:this.value><![CDATA[#{javascript: 
  [{
    "label": "Open",
    "href": "http://www.openntf.org"
  },
  {
    "label": "Search",
    "href": "http://www.google.com"
  }]
}]]></xe:this.value>
                <xe:this.children>
                    <xe:basicLeafNode href="#{item.href}" label="#{item.label}">
                        <xe:this.style><![CDATA[#{javascript:"color:"+(item.label=="Open"?"blue":"red")}]]></xe:this.style>
                    </xe:basicLeafNode>
                </xe:this.children>
            </xe:repeatTreeNode>
        </xe:this.treeNodes>
    </xe:toolbar>

I hope this helps...

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