1

这里我有一个ManagePageSource使用mvvmzk 模式为 TreeView 提供模型。
ManagePageSource有一个内部类Node来保存 treeNode 数据。
Node有一个 name 属性,zk 无法在 zul 文件中读取它。

public class ManagePageSource implements Serializable{

    private static final long serialVersionUID = 1L;

    private TreeModel treeModel = null;

    public TreeModel getTreeModel() {
        TreeNode<Node>[] children = null;
            // create a node
        TreeNode<Node> node = new DefaultTreeNode<Node>(new Node("child"), children);
        // add child node to a node
        node.add(new DefaultTreeNode<Node>(new Node("child2")));
            // create treeModel and set nodes
        treeModel = new DefaultTreeModel(node);

        return treeModel;
    }

    // Inner class for holding tree data
    class Node implements Serializable{
        private static final long serialVersionUID = 1L;
        private String name = null;
        public Node(String name){
            this.name = name;
        }
        public String getName(){
            return name;
        }
        public void setName(String name){
            this.name = name;
        }
    }

}

管理.zul

<window apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('ManagePageSource')">
    <tree model="@load(vm.treeModel)">
        <treecols>
            <treecol label="Path" />
        </treecols>
        <template name="model">
            <treeitem>
                <treerow>
                    <treecell label="@load(each.data.name)" />
                </treerow>
            </treeitem>
        </template>
    </tree>
</window>

错误堆栈

>>org.zkoss.zel.PropertyNotFoundException: Property 'name' not readable on type ManagePageSource$Node
>>  at org.zkoss.zel.BeanELResolver$BeanProperty.read(BeanELResolver.java:409)
>>  at org.zkoss.zel.BeanELResolver$BeanProperty.access$000(BeanELResolver.java:320)

为什么名称在这里不可读?

4

2 回答 2

0

public 类前使用修饰符Node,因为Node类方法不能在外面访问。

 public class ManagePageSource implements Serializable{

    private static final long serialVersionUID = 1L;

    private TreeModel treeModel = null;

    public TreeModel getTreeModel() {
        TreeNode<Node>[] children = null;
            // create a node
        TreeNode<Node> node = new DefaultTreeNode<Node>(new Node("child"), children);
        // add child node to a node
        node.add(new DefaultTreeNode<Node>(new Node("child2")));
            // create treeModel and set nodes
        treeModel = new DefaultTreeModel(node);

        return treeModel;
    }

    // Inner class for holding tree data
 public   class Node implements Serializable{
        private static final long serialVersionUID = 1L;
        private String name = null;
        public Node(String name){
            this.name = name;
        }
        public String getName(){
            return name;
        }
        public void setName(String name){
            this.name = name;
        }
    }

}
于 2013-10-20T13:07:08.370 回答
0

name不可读,因为Node该类不是公开的。改变它解决了这个问题。

于 2013-10-20T14:51:11.250 回答