How to get treedata correctly

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxhh11
    New Member
    • Jan 2007
    • 3

    #1

    How to get treedata correctly

    Hi all, i am using apache tomahawk tree2 component and i get the tree item from DB. The code like:
    Code:
    public TreeNode getTreeData() {
    		List list = getMenuList();
    		TreeNode treeData = new TreeNodeBase("foo-folder", "Inbox", false);
    		Iterator it = list.iterator();
    		HashMap menuTable = new HashMap();
    		while (it.hasNext()) {
    			Eosmenu item = (Eosmenu) it.next();
    			String label = item.getMenuLabel();
    			boolean isLeaf = item.getIsLeaf() != null
    					&& item.getIsLeaf().equalsIgnoreCase("Y");
    			int level = item.getMenuLevel();
    			String menuId = item.getMenuId();
    			String parentsID = item.getParentsId();
    			TreeNodeBase node = new TreeNodeBase();
    			if(isLeaf){
    				node.setType("document");
    			}else{
    				node.setType("bar-folder");
    			}
    			node.setDescription(label);
    			node.setLeaf(isLeaf);
    			menuTable.put(menuId, node);
    			if (level == 1) {
    				treeData.getChildren().add(node);
    			} else {
    				TreeNodeBase pItem = (TreeNodeBase) menuTable.get(parentsID);
    				if (pItem != null)
    					pItem.getChildren().add(node);
    			}
    		}
    		return treeData;
    	}
    This works well only when the items are in the front of their chirdren. How to let it works correctly when the data in the database like :
    id------menuid-------menuname------menulevel------parentid
    1----------b---------------bb-------------------2------------------a
    2----------a---------------aa-------------------1------------------0
Working...