使用RecursiveTreeNodeAdaptor在Seam中创建动态树

使用RecursiveTreeNodeAdaptor在Seam中创建动态树,tree,richfaces,seam,Tree,Richfaces,Seam,我想使用richfaces RecursiveTreeNodeAdaptor在seam中创建动态树 @Entity public class Category extends Item implements Serializable { private static final long serialVersionUID = -1154500438874768209L; private List<Item> children; public void addChild(Item

我想使用richfaces RecursiveTreeNodeAdaptor在seam中创建动态树

@Entity
public class Category extends Item implements Serializable {

private static final long serialVersionUID = -1154500438874768209L;
private List<Item> children;

public void addChild(Item child) {
    if (children == null) {
        children = new ArrayList<Item>();
    }

    if (!children.contains(child)) {
        children.add(child);
    }
}

@OneToMany(cascade = CascadeType.ALL)
public List<Item> getChildren() {
    return children;
}

public void setChildren(List<Item> children) {
    this.children = children;
}
}

 @Entity
 public class Product extends Item implements Serializable {  
    private static final long serialVersionUID = 3975153531436996378L;
 }

 @Inheritance(strategy = InheritanceType.JOINED)
 @Entity
 public class Item {
 private String name;
 private Long id;

 @Id
 @GeneratedValue
 public Long getId() {
    return id;
 }

 public void setId(Long id) {
    this.id = id;
 }

 public String getName() {
    return name;
 }

 public void setName(String name) {
    this.name = name;
 }
}
我的.xhtml页面是

    <ui:define name="body">
    <h:form>
        <rich:panel id="dynamicTreePanel"
            header="Dynamic Tree User Interface">

            <rich:tree>
                <rich:recursiveTreeNodesAdaptor roots="#{provider.organization}"
                    var="rootOrg">
                    <rich:treeNode>
                        <h:outputText value="#{rootOrg.name}" />
                    </rich:treeNode>

                    <rich:recursiveTreeNodesAdaptor roots="#{rootOrg.children}"
                        var="childOrg" nodes="#{childOrg.children}">
                        <rich:treeNode>
                            <h:outputText value="#{childOrg.name}" />
                        </rich:treeNode>
                    </rich:recursiveTreeNodesAdaptor>

                </rich:recursiveTreeNodesAdaptor>
            </rich:tree>
        </rich:panel>
    </h:form>

</ui:define>

当打开deploy页面并单击根目录时,我犯了这个错误


javax.faces.FacesException:javax.el.PropertyNotFoundException:/dynamicItemTree.xhtml@23,52 nodes=“#{childOrg.children}”:类“a.b.c.d.Product”没有属性“children”。

树适配器正在到达一个级别的产品项并尝试读取其子项。此操作失败,因为此类上没有getchildren方法


防止在产品中调用getchildren,或者在产品中实现一个始终返回null(或空数组)的方法。

但我们正在通过实体进行entityMapping。当在Product中实现一个返回null的方法时,程序试图在数据库中创建关于该方法的新列,我接受这个错误;org.hibernate.MappingException:无法确定列:[org.hibernate.mapping.Column(children)]的表:Product中的java.util.List的类型。您可以在Product中创建方法getChildren并返回null。这不会在数据库中创建列。这不是一个“干净”的解决方案,但它有效且快速。我不确定,但据我所知,你也可以直接在treeadaptor中处理。这就是为什么它在那里。
    <ui:define name="body">
    <h:form>
        <rich:panel id="dynamicTreePanel"
            header="Dynamic Tree User Interface">

            <rich:tree>
                <rich:recursiveTreeNodesAdaptor roots="#{provider.organization}"
                    var="rootOrg">
                    <rich:treeNode>
                        <h:outputText value="#{rootOrg.name}" />
                    </rich:treeNode>

                    <rich:recursiveTreeNodesAdaptor roots="#{rootOrg.children}"
                        var="childOrg" nodes="#{childOrg.children}">
                        <rich:treeNode>
                            <h:outputText value="#{childOrg.name}" />
                        </rich:treeNode>
                    </rich:recursiveTreeNodesAdaptor>

                </rich:recursiveTreeNodesAdaptor>
            </rich:tree>
        </rich:panel>
    </h:form>

</ui:define>