1 Reply Latest reply on Oct 28, 2008 1:00 AM by Dana Heath

    Tree how to get TreeNode?

    Stateless Bean Novice

      Can anyone help me to get working with Tree component?

      What I want to do? I got records in db and want to show them in tree, and moving on tree I want to get some record-node and use it?

      Here is my overrided TreeNode class with my db record (id, info etc.)

      public class TreeNodeImpl implements TreeNode {
       private static final long serialVersionUID = -5498990493803705085L;
       private Object data;
       private TreeNode parent;
       public Dictionary dictionary;
       private Map childrenMap = new LinkedHashMap();
       public Object getData() {
       return data;
       public TreeNodeImpl getChild(Object identifier) {
       return (TreeNodeImpl) childrenMap.get(identifier);
       public void addChild(Object identifier, TreeNode child) {
       childrenMap.put(identifier, child);
       public void removeChild(Object identifier) {
       TreeNode treeNode = (TreeNode) childrenMap.remove(identifier);
       if (treeNode != null) {
       public void setData(Object data) {
       this.data = data;
       public TreeNode getParent() {
       return parent;
       public void setParent(TreeNode parent) {
       this.parent = parent;
       public Iterator getChildren() {
       return childrenMap.entrySet().iterator();
       public boolean isLeaf() {
       return childrenMap.isEmpty();
       public Dictionary getDictionary() {
       return dictionary;
       public void setDictionary(Dictionary dictionary) {
       this.dictionary = dictionary;

      Here is my tree "constructor"

       private void init() {
       int counter = 1;
       TreeNodeImpl nodeImpl = new TreeNodeImpl();
       node.addChild(new Integer(counter), nodeImpl);
       TreeNodeImpl nodeImpl6 = new TreeNodeImpl();
       node.addChild(new Integer(counter), nodeImpl6);

      my getter
       public TreeNode getTreeNode() {
       if (rootNode == null) {
       return rootNode;

      and my listener

       public void processSelection(NodeSelectedEvent event) {
       UITree tree = (UITree) event.getComponent();
       Object a = (Object)tree.getTreeNode().getData();
       TreeNode elem = rootNode.getChild(a);

      and here is my problem, why I get only string "a" and "b", can anyone help me what to do to get my object Dictionary?

      Or can anyone show me own source code how to get any own object from node?