You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kurt Edegger <ne...@edegger.com> on 2005/12/01 00:17:09 UTC

Issues adding childNodes to TreeNode elements when using Tree2 component

Hi!

I'd like to use a tree2 component in my JSF application.
The entries are aquired via a DAO from a database. The DAO holds a list
containing the entries in the tree describing the entry itself and the name of
the parent node where it should be attached to (the names of the nodes are
unique).
I'm parsing the list and attach a new TreeNode to the root for each entry where
the parent node is either root or not defined. To add the child nodes, I'm
searching the tree and if the parent node is existing I'm adding a new TreeNode
to the parent one. 
But after I added the child to the parent, the tree.getChildCount() method still
returns the number of nodes without the child. 
What could be the reason for loosing the child node after adding it to the
tree?

Here's a small code snipplet to demonstrate:

nodeIdentifier = "parentNodeIdentifier";
TreeNode parentNode = getNode(treeData, nodeIdentifier);
TreeNodeBase groupNode=null;
if (parentNode!=null){
  int index = treeData.getChildren().indexOf(parentNode);
  TreeNode pNode2 = (TreeNode) treeData.getChildren().get(index);
  //pNode2 is the same as parentNode as expected
  nodeIdentifier = "childNodeIdentifier";
  groupNode = new TreeNodeBase(type, name, nodeIdentifier, false);
  //[1]
  parentNode.getChildren().add(groupNode);
  //[2]
}

treeData holds the root of the tree as a simple TreeNodeBase element.
parentNode.getChildCount() return 0 at [1] and 1 at [2] as expected,
but treeData.getChildCount() returns 1 at both positions of the code.

Even if I add the parentNode explicitely again to the tree, the number of childs
in the tree is increased only by 1 (the parentnode) and not by 2
(parent+child).

What am I missing here? Is there an easier way to construct a tree which has
more than one level of children?

Any help appreciated.

Thank you,

   Kurt