0

Error updating treenode / only one treerow is allowed

asked 2012-05-14 11:07:17 +0800

cocoes gravatar image cocoes flag of Spain
94 6

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?

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-05-18 09:00:50 +0800

cocoes gravatar image cocoes flag of Spain
94 6

updated 2012-05-18 09:17:52 +0800

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?

link publish delete flag offensive edit

answered 2012-06-25 06:57:14 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2012-06-25 07:07:37 +0800

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>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-05-14 11:07:17 +0800

Seen: 236 times

Last updated: Jun 25 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More