Grails Richui Plugin – Supporting Expanded on TreeView

The TreeView support in the Grails Richui plugin does not support the setting of the “expanded” property. With a minor modification you can correct this.

What I want to do in my controller (based on the plugin’s example):

    .
    .
    .
    def xml = new MarkupBuilder(writer)
    xml.person(name: "John Doe"){
        books(name: "Books", expanded: true){
            book(name:"Book 1")
            //Optional id
            book(name:"Book 2", id: 1)
        }
    }
    .
    .
    .

To achieve this I modified de.andreasschmitt.richui.taglib.renderer.TreeViewRenderer in the src/groovy/de/andreasschmitt/richui/taglib/renderer directory where the plugin is installed. The renderTagContent method writes out a function to the page called createNode that is used elsewhere as its name implies. I added an “expand” argument to it and use that for setting the expanded property, so that the relevant lines now look like this.

    builder.yieldUnescaped "    function createNode(text, id, icon, pnode, expand){\n"
    builder.yieldUnescaped "        var n = new YAHOO.widget.TextNode(text, pnode, false);\n"
    builder.yieldUnescaped "        n.labelStyle=icon;\n"
    builder.yieldUnescaped "        if (expand == \"true\"){\n"
    builder.yieldUnescaped "            n.expanded = true;\n"
    builder.yieldUnescaped "        }\n"

Then on the references to it elsewhere in the code (there are two in the version I am using) I pass the expanded value from the XML, so it resembles this.

    builder.yieldUnescaped "    createNode(\"" + it.@name + "\", \"" + it?.@id + "\", \"" + it.@icon + "\", $parent, \"" + it.@expanded + "\");\n"

Leave a comment