使用recursiveTreeNodesAdaptor在Seam中创建动态树

时间:2011-09-15 12:21:25

标签: tree richfaces seam

我想使用richfaces recursiveTreeNodesAdaptor在接缝中创建动态树。我的实体类在这里;

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

我在这里使用这个课程;

@Name("provider")
@Scope(ScopeType.APPLICATION)
public class OrganisationProvider implements Serializable {


private static final long serialVersionUID = 1L;

    public Category organization;

public OrganisationProvider() {
    if (organization == null) {
        setOrganization(createOrganization());

    }

}

public Category createOrganization() {
    Category ROOT = new Category();
    Category computerC = new Category();
    Category printerC = new Category();
    Category telephoneC = new Category();

    Product product = new Product();

    ROOT.setName("ROOT");
    computerC.setName("BilgisayarC");
    printerC.setName("YazıcılarC");
    telephoneC.setName("TelephoneC");

    computerC.addChild(printerC);

    ROOT.addChild(computerC);
    ROOT.addChild(product);

    return ROOT;
}

public void setOrganization(Category organization) {
    this.organization = organization;
}

public Category getOrganization() {
    return organization;
}
}

和我的.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>

当部署页面并单击root时,我会收到此错误;

javax.faces.FacesException:javax.el.PropertyNotFoundException:/dynamicItemTree.xhtml @ 23,52 nodes =“#{childOrg.children}”:类'abcdProduct'没有属性'children'。< / p>

1 个答案:

答案 0 :(得分:0)

树适配器在一个级别中到达Product项目并尝试读取其子项。这失败了,因为这个类上没有getchildren方法。

要么阻止调用getchildren以防它是Product,要么在Product中实现一个总是返回null(或空数组)的方法