This content has been marked as final.
Show 1 reply
-
1. Re: rich tree crashes with a lot of data
kyuss Jun 17, 2007 10:55 AM (in response to kyuss)really no idea? maybe i post some code, initialising with some stupid testcode:
<rich:panel style="height:1020px"> <rich:tree switchType="client" style="width:300px" value="#{pathwayBean.pathwayTree}" var="item" nodeFace="#{item.type}"> <rich:treeNode type="library"> <h:outputText value="#{item.type}" /> </rich:treeNode> <rich:treeNode type="pathway"> <h:outputText value="#{item.name}" /> </rich:treeNode> <rich:treeNode type="organism"> <h:outputText value="#{item.name}" /> </rich:treeNode> </rich:tree> </rich:panel>
bean code:public Object getPathwayTree() { return new Library(); }
tree-classes:package amedina.test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import org.richfaces.component.TreeNode; public class Library implements TreeNode { /** * */ private static final long serialVersionUID = 1578725580087059066L; /** * */ private Map pathways = null; private Object state1; //private Object state2; private List listPathway; public Library(List l){ this.listPathway = l; } private Map getPathways() { if (this.pathways==null) { initData(); } return this.pathways; } public void addPathway(Pathway pw) { addChild(Long.toString(artist.getId()), pw); pw.setParent(this); } public void addChild(Object identifier, TreeNode child) { getPathways().put(identifier, child); } public TreeNode getChild(Object id) { return (TreeNode) getPathways().get(id); } public Iterator getChildren() { return getPathways().entrySet().iterator(); } public Object getData() { return this; } public TreeNode getParent() { return null; } public boolean isLeaf() { return getPathways().isEmpty(); } public void removeChild(Object id) { getPathways().remove(id); } public void setData(Object data) { } public void setParent(TreeNode parent) { } public String getType() { return "library"; } private long nextId = 0; private long getNextId() { return nextId++; } private Map pathCache = new HashMap(); private Pathway getPathwayByName(String name, Library library) { Pathway pathway = (Pathway)pathCache.get(name); if (pathway==null) { pathway = new Pathway(getNextId()); pathway.setName(name); pathCache.put(name, pathway); library.addPathway(pathway); } return pathway; } private void initData() { pathways = new HashMap(); for(int i = 0;i<50;i++){ Pathway path = getPathwayByName("PATH_"+i,this); for(int j=0;j<50;j++){ Organism org = new Organism(getNextId()); org.setName("ORG_"+i+"."+j); path.addOrganism(org); } } } public Object getState1() { return state1; } public void setState1(Object state1) { this.state1 = state1; } }
Pathway-class:package amedina.test; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.richfaces.component.TreeNode; public class Pathway implements TreeNode { /** * */ private static final long serialVersionUID = -2411448524743271268L; private long id; private Map organisms = new HashMap(); private String name; private Library library; public Pathway(long id) { this.id = id; } public void addOrganism(Organism org) { addChild(Long.toString(org.getId()), org); org.setParent(this); } public void addChild(Object identifier, TreeNode child) { organisms.put(identifier, child); } public TreeNode getChild(Object id) { return (TreeNode) organisms.get(id); } public Iterator getChildren() { return organisms.entrySet().iterator(); } public Object getData() { return this; } public TreeNode getParent() { return library; } public boolean isLeaf() { return organisms.isEmpty(); } public void removeChild(Object id) { organisms.remove(id); } public void setData(Object data) { } public void setParent(TreeNode parent) { library = (Library) parent; } public long getId() { return id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Library getLibrary() { return library; } public void setLibrary(Library library) { this.library = library; } public String getType() { return "pathway"; } }
Organism-class:package amedina.test; import java.util.ArrayList; import java.util.Iterator; import org.richfaces.component.TreeNode; public class Organism implements TreeNode { /** * */ private static final long serialVersionUID = -760391169139121906L; /** * */ private long id; private String name; private Pathway pathway; public Organism(long id) { this.id = id; } public void addChild(Object identifier, TreeNode child) { throw new UnsupportedOperationException("Organisms do not have children"); } public TreeNode getChild(Object id) { throw new UnsupportedOperationException("Organisms do not have children"); } public Iterator getChildren() { // TODO: Fix me! return new ArrayList().iterator(); // work around limitation for TreeNode } public Object getData() { return this; } public TreeNode getParent() { return pathway; } public boolean isLeaf() { return true; } public void removeChild(Object id) { throw new UnsupportedOperationException("Organisms do not have children"); } public void setData(Object data) { } public void setParent(TreeNode parent) { this.pathway = (Pathway) parent; } public Pathway getPathway() { return pathway; } public void setPathway(Pathway artist) { this.pathway = artist; } public String getName() { return name; } public void setName(String title) { this.name = title; } public long getId() { return id; } public String getType() { return "organism"; } }
The problem reamains, if i use 'ajax' or 'server' switchtype.
Is it a known bug, that initialiation of the tree takes so long with so many data, or am i doin' something wrong?