使用 recursiveTreeNodesAdaptor 在 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节点=“#{childOrg.children}”:类“abcdProduct”没有属性“children”。
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'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
树适配器正在到达一个级别中的产品项并尝试读取其子项。这会失败,因为此类上没有 getchildren 方法。
要么阻止调用 getchildren(如果它是 Product),要么在 Product 中实现始终返回 null(或空数组)的方法
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)