ZK内部类树属性不可读 [英] ZK inner class tree property not readable

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

问题描述

我有与此问题几乎相同的问题:在TreeModel的内部类上不可读的属性

I have almost the same problem as this question: Property not readable on a inner class in a TreeModel

但是相同的解决方案似乎不适用.

But the same solution seems not applicable.

我有一棵树,当我实现Entity和TreeModel时,它们工作得很好,在我的.zul文件中,我在树单元中找不到数据"属性.

I have a tree, and as I implemented my Entity, and my TreeModel, and they are working just fine, on my .zul file my "data" property isn't found on the treecell.

以下是一些代码:

-运行@AfterCompose的结构实现:

-The structure implementation, that runs @AfterCompose:

 private void montarEstrutura(){

    Unidade ub1 = new Unidade();
    ub1.setParent(null);
    ub1.setNumero("NBase");
    ub1.setDescricao("DBase");

    Unidade ub2 = new Unidade();
    ub2.setParent(ub1);
    ub2.setNumero("N002");
    ub2.setDescricao("D002");

        Unidade ub4 = new Unidade();
        ub4.setParent(ub2);
        ub4.setNumero("N004");
        ub4.setDescricao("D004");

            Unidade ub6 = new Unidade();
            ub6.setParent(ub4);
            ub6.setNumero("N006");
            ub6.setDescricao("D006");

            Unidade ub7 = new Unidade();
            ub7.setParent(ub4);
            ub7.setNumero("N007");
            ub7.setDescricao("D007");

            Unidade ub8 = new Unidade();
            ub8.setParent(ub4);
            ub8.setNumero("N008");
            ub8.setDescricao("D008");

        Unidade ub5 = new Unidade();
        ub5.setParent(ub2);
        ub5.setNumero("N005");
        ub5.setDescricao("D005");

    Unidade ub3 = new Unidade();
    ub3.setParent(ub1);
    ub3.setNumero("N003");
    ub3.setDescricao("D003");


    List<Unidade> lub3 = new ArrayList<Unidade>();
    lub3.add(ub6);
    lub3.add(ub7);
    lub3.add(ub8);

    ub4.setUnidades(lub3);

    List<Unidade> lub2 = new ArrayList<Unidade>();
    lub2.add(ub4);
    lub2.add(ub5);
    ub2.setUnidades(lub2);

    List<Unidade> lub1 = new ArrayList<Unidade>();
    lub1.add(ub2);
    lub1.add(ub3);
    ub1.setUnidades(lub1);

    unidadeTreeModel = new UnidadeTreeModel(ub1);
    tree.setModel(unidadeTreeModel);

}

-实体很长,所以我将其剪裁:

-The entity is pretty long, so I'll cut it:

@Entity
@Audited
public class Unidade extends AbstractSuseTools{

private String numero;
private String descricao;

    @OneToMany
private List<Unidade> unidades = new LinkedList<Unidade>();

    public String getNumero() {
    return numero;
}

public void setNumero(String numero) {
    this.numero = numero;
}

public String getDescricao() {
    return descricao;
}

public void setDescricao(String descricao) {
    this.descricao = descricao;
}
public List<Unidade> getUnidades() {
    return unidades;
}

public void setUnidades(List<Unidade> unidades) {
    this.unidades = unidades;
}
}

这是.zul文件,该文件不读取实体的属性:

And here's the .zul file, that does not reads the property of the entity:

<div apply="org.zkoss.bind.BindComposer"
     viewModel="@id('vm') @init('br.com.simplesmenteuse.viewmodel.basico.OrganizacaoViewModel')"    >
   <tree id="tree" model="@load(vm.unidadeTreeModel)" selectedItem="@bind(vm.unidadeSelected)" >
        <treecols>
            <treecol width="100px" label="Editar" />
            <treecol width="100px" label="Excluir" />
            <treecol hflex="4" label="Número" />
            <treecol hflex="1" label="Nome" />
        </treecols>
        <template name="model">
            <treeitem>
                <treerow>
                    <treecell label="Editar"/>
                    <treecell label="Excluir"/>
                    <treecell label="@load(each.numero)"/>
                    <treecell label="@load(each.descricao)"/>
                </treerow>
            </treeitem>
        </template>
    </tree>

我的TreeModel:

My TreeModel:

    public class UnidadeTreeModel extends AbstractTreeModel<Unidade> {
    /**
     *
     */
    private static final long serialVersionUID = 3854683349236034878L;

    public UnidadeTreeModel(Unidade unidade){
        super(unidade);
    }

    public boolean isLeaf(Unidade node) {
        return getLevel(node.toString()) >= 4; //at most 4 levels;
    }
    public Unidade getChild(Unidade parent, int index) {
        if(((Unidade)parent).getUnidades() != null && ((Unidade)parent).getUnidades().size() > index)
            return ((Unidade)parent).getUnidades().get(index);
        else
            return null;
    }
    public int getChildCount(Unidade parent) {
        return (((Unidade)parent).getUnidades() != null)?((Unidade)parent).getUnidades().size():0;
    }
    public int getIndexOfChild(Unidade parent, Unidade child) {
        for (int i  = 0; i<parent.getUnidades().size();i++) {
            if (child.equals(parent.getUnidades().get(i))) { return i;}
        }
        return -1; //or throw exception what you want.
    }
    private int getLevel(String data) {
        for (int i = -1, level = 0;; ++level)
            if ((i = data.indexOf('.', i + 1)) < 0)
                return level;
    }

};

错误:

现在它不显示任何错误,只是不获取对象的子级别.

Now it don't show any errors, just don't get the sub-levels of the object.

我真的不知道树是怎么完成的,所以我不明白为什么它不可读.

I don't really get how it's all done by the tree, so I can't get why it isn't been readable.

推荐答案

只需在zul中删除此数据:

Just remove this data in your zul:

 <treecell label="@load(each.numero)"/>
   <treecell label="@load(each.nome)"/>

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

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