Dynamically Loading TreeNode Children - Tree Will Expand Listener
Hi,
I'm trying to dynamically load the children of a tree node as it expands, to save loading the entire tree at startup.
I've done this in the past in Swing with a TreeWillExpandListener on the tree, adding a tree node with 'loading' as the text and then when the will expand event is fired, removing the loading node and replacing it will the actual childs nodes created and loaded from the db.
Does anyone know how to do this in Creator?
many thanks,
Tony
# 1
I created a simplified version of what you want to do. Maybe it will help.
Make sure your node has no children in the Design View. If it has children in the Design View (and thus in the JSP), these nodes will not get cleared out.
The method that is bound to the actionListener attribute gets called when the user expands or contracts a node. Create a method to be called when this happens:
public void treeNode1_openClose(javax.faces.event.ActionEvent event) {
if (!treeNode1.isExpanded()) {
List innerChildren = treeNode1.getChildren();
innerChildren.clear();
// Create a new trip node
TreeNode subNode = new TreeNode();
subNode.setId("subnode3");
subNode.setText("Sub Node 3");
innerChildren.add(subNode);
}
}
In the properties window for the tree node, make sure the Expanded checkbox is clear (not checked)
In the properties window for the tree node, set the actionListener property to the method, like this:
#{Page2.treeNode1_openClose}
Add something like the following to the init method:
// add a dummy node so that the expand button appears
List innerChildren = treeNode1.getChildren();
innerChildren.clear();
// Create a new trip node
TreeNode subNode = new TreeNode();
subNode.setId("dummyNode");
subNode.setText("Dummy Node");
innerChildren.add(subNode);