-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi!
I'm testing ZK 6.0.1 functionalities, and I've found an error when updating TreeNode's data. My problem is that when I try to update the children like this:
childrenNode.setData(childrenRow)
, or the parent node like this:
parentNode.setData(parentRow)
, it throws an exception:
Only one treerow is allowed: <Treeitem q3CP5c0>
Tree initialization:
synchronized(modelTree){ RowInformation row = new RowInformation("some info",someboolean); DefaultTreeNode node=new DefaultTreeNode(row, new DefaultTreeNode[] { new DefaultTreeNode(new RowInformation("some info",someboolean)), new DefaultTreeNode(new RowInformation("some info",someboolean)), new DefaultTreeNode(new RowInformation("some info",someboolean)), new DefaultTreeNode(new RowInformation("some info",someboolean)), }); ((DefaultTreeNode)((DefaultTreeModel)modelTree).getRoot()).add(node); }
Tree update:
synchronized(modelTree) { DefaultTreeNode rootNode=(DefaultTreeNode)modelTreeMC.getRoot(); Iterator it=rootNode.getChildren().iterator(); DefaultTreeNode parentNode; RowInformation parentRow; while(it.hasNext()) { i++; parentNode= (DefaultTreeNode)it.next(); parentRow=(RowInformation)parentNode.getData(); if (some_validation) { // do things.. // update row parentNode.setData(parentRow); // Update children if (parentNode.getChildren()!=null) { DefaultTreeNode childrenNode; RowInformation childrenRow; for (int index = 0; index < parentNode.getChildCount(); index++) { childrenNode=(DefaultTreeNode)parentNode.getChildAt(index); childrenRow=(RowInformation)childrenNode.getData(); // modify children Row information childrenNode.setData(childrenRow); parentNode.insert(childrenNode,index); } } rootNode.insert(parentNode, i); } } }
I also initialize the zul like this:
<tree id="myTree" width="100%"> <treecols sizable="true"> <treecol label="MyColumn1" /> </treecols> <treechildren> </treechildren> </tree>
What I'm doing wrong?
It seems to be solved ad the beginning of rendering like this:
public void render(Treeitem treeItem, Object data, int arg2) throws Exception { DefaultTreeNode treeNode = (DefaultTreeNode) data; treeItem.setValue(treeNode); Treerow tr = treeItem.getTreerow(); if(tr == null) { tr = new Treerow(); } else { tr.getChildren().clear(); } treeItem.appendChild(tr); ....
By the way, I've noticed that when I update a node, it closes automatically it's children. An also, that any update on its children it's not rendered or refreshed on the customer browser.
Is there any way to avoid closing the treenode and forcing the children rendering?
Hi vicent,
You need to store open statue to date bean, and restore open statue from data bean.
BTW, you can use template for Tree render, please refer to http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVC/View/Template/Tree_Template
and you cantry to use with MVVM
<template name="model" var="node"> <treeitem open="@bind(node.data.open)"> <treerow> <treecell label="@load(node.data.path)"></treecell> <treecell label="@load(node.data.description)"></treecell> </treerow> </treeitem> </template>
Asked: 2012-05-14 11:07:17 +0800
Seen: 236 times
Last updated: Jun 25 '12