Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Possible bug in Databound Tree

    I may have found a bug in the Tree() widget or at least I found something that's unintuitive. I have a databound Tree that represents my left navigation and it works great.

    I want to programmaticly access the nodes within my tree. On my first attempt I wrote some code to get the nodes and was getting a ClassCastException inside the _isc methods (smartGWT).

    myNavTreeGrid.getTree().getAllNodes() -> ClassCastException

    Something funky is going on there. After looking through the API a bit more I found an alternative way of doing this:

    myNavTreeGrid.getData().getData() -> correctly returns ListGridRecord[]

    however, the array of records is null when my tree is happily sitting on the screen and working fine.

    So then i called myNavTreeGrid.getData().getRoot() which worked, however there's no getChildren() method so I can't loop over the child records.

    Ultimately I just want to get at the ListGridRecords that are returned by the DataSource attached to my Tree.

    Thoughts?

    #2
    I came back to this after about a week and managed to find a work around to the bugs in SmartGWT. I still think this should be fixed or at least clarified in the docs as to what is going on.

    There's a dynamic cast function within smartgwt and it checks against a list of classes that it is allowed to cast to and for some reason it doesn't work with ListGridRecords even though that is the type of the Object it has.

    After working with Firebug to figure out what exactly was going on under the covers, I found the following code to work to find a particular node in a databound TreeGrid.

    Code:
    	public void actOnTreeGridNode(String id)
    	{
    		RecordList rl = myTreeGrid.getDataAsRecordList();
    		Record nodes[] = rl.toArray();
    		Record theNode = findNode(id, nodes);
    		
                    // now you have it and can do whatever you want to it
    	}
    
    	private Record findNode(String id, Record list[])
    	{
    		Record rtn = null;
    		for (int i = 0; i < list.length; i++) {
    			if (list[i].getAttribute("id")).equals(id)) {
    				return list[i];
    			}
    			Record children[] = list[i].getAttributeAsRecordArray("children");
    
    			if (children != null && children.length > 0) {
    				rtn = findSection(id, children);
    				if (rtn != null) return rtn;
    			}
    		}
    
    		return rtn;
    	}
    If you have a massive tree, you can add your own tree walking optimizations, but a simple straight down walk works for me.

    Comment

    Working...
    X