Uploaded image for project: 'ZK JSP'
  1. ZK JSP
  2. ZKJSP-8

Dynamically and in-memory created tree does not open lower leafs

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Normal Normal
    • None
    • None
    • None
    • ZK 6.0.0, Zul jsp 2.0

      When creating a tree demo according to Small Talk http://books.zkoss.org/wiki/Small_Talks/2007/August/ZK_Tree_Model
      the tree is created and displays the top-level nodes, but clicking on the nodes doesn't open it. Is it a problem, for example, in the TreeDataListener?

      Similarly, when constructing and displaying an in-memory tree according to Small Talk http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVC/Model/Tree_Model - Example: In-Memory Tree with DefaultTreeModel - the tree displays but doesn't open the lower leafs.

      jsp is:
      <tiles:putAttribute name="body">
      <z:page zscriptLanguage="java">
      <z:tree id="tree" width="1100px" rows="20" hflex="1" vflex="1" model="${tm}">
      <z:treecols sizable="true" width="1100px" hflex="1">
      <z:treecol width="300px" label="Name"/>
      </z:treecols>
      </z:tree>
      </z:page>

      </tiles:putAttribute>

      and model data is:
      ArrayList al = new ArrayList();
      int i = 0;
      for (; i < 1000; i++)

      { Object obj = "" + i; al.add(obj); }

      BinaryTreeModel tm = new BinaryTreeModel(al);

      and model is:
      public class BinaryTreeModel extends AbstractTreeModel {

      private ArrayList _tree = null;

      /**

      • Constructor
      • @param tree the list is contained all data of nodes.
        */
        public BinaryTreeModel(List tree) { super(tree.get(0)); _tree = (ArrayList) tree; }

      // – TreeModel --//
      public Object getChild(Object parent, int index) {
      int i = _tree.indexOf(parent) * 2 + 1 + index;
      if (i >= _tree.size())

      { return null; }

      else

      { return _tree.get(i); }

      }

      // – TreeModel --//
      public int getChildCount(Object parent) {
      int count = 0;
      if (getChild(parent, 0) != null)

      { count++; }
      if (getChild(parent, 1) != null) { count++; }

      return count;
      }

      // – TreeModel --//
      public boolean isLeaf(Object node)

      { return (getChildCount(node) == 0); }

      }

            benbai benbai
            iProc iProc
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: