ZK - Open Source Ajax Java FrameworkZK - Open Source Ajax Java Framework

Working with Tree [BASIC]

Fabiosimao
20 Dec 2011 16:36:23 GMT
20 Dec 2011 16:36:23 GMT

I have couple basic doubts about how to correctly build trees using the composer.

If i wanna build a tree in the ZUL file i could do something like this

<tree>
   <treecols>
      <treecol label="foo" ></treecol>
   </treecols>
   <treechildren id="data">
       <treeitem>
         <treerow>
           <treecell label="test"></treecell>
         </treerow>
       </treeitem>
   </treechildren>
</tree>

And it works just fine..

But when i try to add more stuff using the controller for that page, it doesnt change a thing. Here is an extract from the controller:

Treeitem item = new Treeitem();

	Treerow tr = new Treerow();
	item.appendChild(tr);
	tr.appendChild(new Treecell("test"));
	data.appendChild(item);
        //data is a treechildren, autowired

This code doesnt show up anything on my tree. I assume this isnt the right way to manage tree components, since i didnt apply any model or renderer.

My doubt is, do i need to apply some model/renderer whenever i want to manage a tree from the composer? I already read the documentation but the doubt still remains mainly because of when i build tree in ZUL page i dont need to specify any model etc.

Thanks in advance.

twiegandTop Contributor
20 Dec 2011 17:30:46 GMT
20 Dec 2011 17:30:46 GMT

Fabiosimao,

Your code seems to work for me.  I took your example and made it work as follows:

Controller


import org.zkoss.zk.ui.util.GenericForwardComposer;
	
public class MyController extends GenericForwardComposer {
	Treechildren data;
	
	public void onClickAdd(Event event) {
		Treeitem item = new Treeitem();
		Treerow tr = new Treerow();
		item.appendChild(tr);
		tr.appendChild(new Treecell("test1"));
		data.appendChild(item);
	}
}

Zul


<window apply="MyController">
	<tree>
		<treecols>
			<treecol label="foo"></treecol>
		</treecols>
		<treechildren id="data">
			<treeitem>
				<treerow>
					<treecell label="test"></treecell>
				</treerow>
			</treeitem>
		</treechildren>
	</tree>
	<button label="Add" forward="onClick=onClickAdd()"/>
</window>

Hope that helps,

Todd

Fabiosimao
20 Dec 2011 17:35:44 GMT
20 Dec 2011 17:35:44 GMT

Thank you very much for your reply. Indeed, my code was correct but i did one stupid mistake: i applied the controller on the zk tag and didnt realize it was being ignored, tried to apply it on the page tag also and didnt work so i created a window to apply it.

Thank you again ;)