By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,468 Members | 1,865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,468 IT Pros & Developers. It's quick & easy.

How to get treedata correctly

P: 3
Hi all, i am using apache tomahawk tree2 component and i get the tree item from DB. The code like:
Expand|Select|Wrap|Line Numbers
  1. public TreeNode getTreeData() {
  2.         List list = getMenuList();
  3.         TreeNode treeData = new TreeNodeBase("foo-folder", "Inbox", false);
  4.         Iterator it = list.iterator();
  5.         HashMap menuTable = new HashMap();
  6.         while (it.hasNext()) {
  7.             Eosmenu item = (Eosmenu) it.next();
  8.             String label = item.getMenuLabel();
  9.             boolean isLeaf = item.getIsLeaf() != null
  10.                     && item.getIsLeaf().equalsIgnoreCase("Y");
  11.             int level = item.getMenuLevel();
  12.             String menuId = item.getMenuId();
  13.             String parentsID = item.getParentsId();
  14.             TreeNodeBase node = new TreeNodeBase();
  15.             if(isLeaf){
  16.                 node.setType("document");
  17.             }else{
  18.                 node.setType("bar-folder");
  19.             }
  20.             node.setDescription(label);
  21.             node.setLeaf(isLeaf);
  22.             menuTable.put(menuId, node);
  23.             if (level == 1) {
  24.                 treeData.getChildren().add(node);
  25.             } else {
  26.                 TreeNodeBase pItem = (TreeNodeBase) menuTable.get(parentsID);
  27.                 if (pItem != null)
  28.                     pItem.getChildren().add(node);
  29.             }
  30.         }
  31.         return treeData;
  32.     }
  33.  
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
Jan 31 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.