Creating dynamic tree in Seam with using recursiveTreeNodesAdaptor
I want to create dynamic tree in seam with using richfaces recursiveTreeNodesAdaptor.My entity classes is here ;
@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;
}
}
and i use this class into here;
@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;
}
}
and my .xhtml page is ;
<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>
When the deploy page and click the root, I take this error;
javax.faces.FacesException: javax.el.PropertyNotFoundException: /dynamicItemTree.xhtml @23,52 nodes="#{childOrg.children}": The class 'a.b.c.d.Product' does not have the property 'children'.
The tree adaptor is reaching a Product item in one level and tries to read its children. This fails because there is no method getchildren on this class.
Either prevent calling getchildren in case its a Product or implement a method in Product that always returns null ( or empty array)
精彩评论