属性在 TreeModel 中的内部类上不可读 [英] Property not readable on a inner class in a TreeModel

查看:29
本文介绍了属性在 TreeModel 中的内部类上不可读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Here i have a ManagePageSource which provide Model for TreeView using mvvm pattern of zk.
ManagePageSource has a inner class Node to hold treeNode Data.
Node has a name property and zk is not able to read it in zul file.

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


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)

为什么名称在此处不可读?

Why name is not readable here ?

推荐答案

Node类之前使用修饰符public,因为Node类的方法无法访问外部.

Use modifier public before Node class,Because of the Node class method can't access outside.

 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;
        }
    }

}

这篇关于属性在 TreeModel 中的内部类上不可读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆