How to get all the selected items inside a tree model

asked 2013-02-04 15:10:40 +0800

kazma gravatar image kazma
15 3

am trying to get all the selected items inside a tree model with the following ZKscript:

Iterator it = tree.getSelectedItems().iterator();

    while (it.hasNext()){
        Treeitem treeitem = it.next();
        alert("you select item - "+treeitem.getLabel());

but all it returns the first level of my tree knowing that my tree has three or four levels or childs how can i retrieve the label of those childs with zscript plz!!!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-02-04 17:49:40 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8

updated 2013-02-05 08:24:11 +0800

You can refer following demo example...

ViewModel for tree example

public class TreeSelectionVM {

    private TreeModel<TreeNode<String>> itemTree;
    private String pickedItem;
    //omit getter and setter for brevity

And ZUL Page code

<window apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('org.zkoss.reference.developer.mvvm.collection.TreeSelectionVM')">
    <tree id="tree" model="@bind(vm.itemTree) " width="600px"
            <treecol label="name" />
            <treecol label="index" />
        <template name="model" var="node" status="s">
            <treeitem open="@bind(node.open)">
                    <treecell label="@bind(node.data)" />
                    <treecell label="@bind(s.index)" />

For more information you can refer ZK Official Document

For Single selection of item developer can use


and for multiple item selection


I think you did not checked link posted by me See there

Binding to Selected Item

link publish delete flag offensive edit


does this work for for getting only one selected item or it returns all the selected items in the tree ??? thank you very much!

kazma ( 2013-02-04 19:30:49 +0800 )edit

check I Edited my answer.

sjoshi ( 2013-02-05 05:08:02 +0800 )edit

could u plz be more specific on how to implement in the view Model its not clear to me plus there is no such tag as "selectedItems" in a tree i just checked thank u!

kazma ( 2013-02-05 07:19:52 +0800 )edit

Answer edited again please check link added in answer

sjoshi ( 2013-02-05 08:25:05 +0800 )edit

yes i did but am using a Select composer (MVC) i cannot use binding do you have a solution for me plz ?

kazma ( 2013-02-05 08:30:10 +0800 )edit
Your answer
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

1 follower



Asked: 2013-02-04 15:10:40 +0800

Seen: 90 times

Last updated: Feb 05 '13

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