PDA

View Full Version : [FIXED] TreePanel with multiple root nodes async loaded bug



momalley
8 Jul 2009, 1:25 PM
There is a bug when loading a tree asynchronously that has multiple root nodes.

If you have an empty tree on the page and use an RPC call to load the entire tree, a tree with multiple root nodes will display only the first node and throw this error:


[ERROR] Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (TypeError): 'firstChild' is null or not an object
number: -2146823281
description: 'firstChild' is null or not an object
at com.google.gwt.dom.client.DOMImpl.getFirstChildElement(Native Method)
at com.google.gwt.dom.client.Element$.getFirstChildElement$(Element.java:169)
at com.extjs.gxt.ui.client.widget.treepanel.TreePanel.doUpdate(TreePanel.java:936)
at com.extjs.gxt.ui.client.widget.treepanel.TreePanel$3.handleEvent(TreePanel.java:1390)
at com.extjs.gxt.ui.client.util.DelayedTask$1.run(DelayedTask.java:30)
at com.extjs.gxt.ui.client.util.DelayedTask.delay(DelayedTask.java:52)
at com.extjs.gxt.ui.client.widget.treepanel.TreePanel.update(TreePanel.java:1394)
at com.extjs.gxt.ui.client.widget.treepanel.TreePanel.onAdd(TreePanel.java:1017)
at com.extjs.gxt.ui.client.widget.treepanel.TreePanel$1.storeAdd(TreePanel.java:281)
at com.extjs.gxt.ui.client.store.StoreListener.handleEvent(StoreListener.java:22)
at com.extjs.gxt.ui.client.store.StoreListener.handleEvent(StoreListener.java:1)
at com.extjs.gxt.ui.client.event.BaseObservable.callListener(BaseObservable.java:176)
at com.extjs.gxt.ui.client.event.BaseObservable.fireEvent(BaseObservable.java:96)
at com.extjs.gxt.ui.client.store.TreeStore.doInsert(TreeStore.java:796)
at com.extjs.gxt.ui.client.store.TreeStore.insert(TreeStore.java:490)
at com.extjs.gxt.ui.client.store.TreeStore.add(TreeStore.java:163)As far as I can tell, the bug is in TreePanel.onAdd line 1013. When the store has nodes added to it, it will loop over all the root nodes and create a string of all their html. This html string is then put into a div. However, on the buggy line, only the first child of the div is added to the tree. This is the first root node. The other root nodes are ignored. So when the code moves on to update the nodes in the tree, there is no element to update for any node beyond the first one. This causes the above error.

GXT version 2.0 final
Hosted mode and web mode
IE and Firefox
Windows XP

Sample Code:


public class Test implements EntryPoint {

public void onModuleLoad() {

final TreeStore<ModelData> store = new TreeStore<ModelData>();
final TreePanel<ModelData> tree = new TreePanel<ModelData>(store);
tree.setDisplayProperty("name");
tree.setWidth(250);

RootPanel.get().add(tree);
RootPanel.get().add(new Button("Add Tree", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
Folder model = TestData.getTreeModel();
store.add(model.getChildren(), true);
}
}));
}
}

This will add a button to the page, and when you click it, it should display the entire tree from the basic tree example. Instead it shows only the first node and throws an exception.

sven
8 Jul 2009, 1:26 PM
Please read the bugforum guidelines and add the missing details to your post

momalley
9 Jul 2009, 7:27 AM
Added sample code to illustrate the problem.

sven
10 Jul 2009, 7:48 AM
Fixed in SVN.