房产无法读取上TreeModel中一个内部类(Property not readable on a

2019-10-18 19:18发布

这里我有一个ManagePageSource其使用树视图提供模型mvvm ZK的图案。
ManagePageSource有一个内部类Node持有treeNode的数据。
Node有一个名称属性和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;
        }
    }

}

Manage.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)

为什么名字是不是可读吗?

Answer 1:

name是不可读的,因为Node类是不公开的。 改变这种固定的问题。



Answer 2:

使用修饰public面前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;
        }
    }

}


文章来源: Property not readable on a inner class in a TreeModel