dynamic tree, unable to display child nodes
srama1 Oct 1, 2008 1:51 AMHello,
I am working on trying to get dynamic tree working, where I am reading the textnode from the database. I have the parent node rendered but it gives be an error that it cannot find the childnode in my code. I know I have incorrectly assigned value to node. Can anyone please explain how to assign child node that’s queried.
One more, I have the database schema listed below. I want to query the nodeText for children and display at associated parentnode. Any pointers on this will be appreciated.
Configuration.xhtml
<rich:tree switchType="ajax" componentState="#{configurationTreeManager.treeState}"> <rich:recursiveTreeNodesAdaptor id="config" roots="#{configurationTreeManager.rootNodes}" var="config" nodes="#{config.childNodes}" > <rich:treeNode> <h:outputText value="#{config.nodeText}" /> </rich:treeNode> </rich:recursiveTreeNodesAdaptor> </rich:tree>
ConfigurationTreeManager.java
@Scope(ScopeType.CONVERSATION) @Name("configurationTreeManager") public class ConfigurationTreeManager { @In protected FacesMessages facesMessages; @In private EntityManager entityManager; private HtmlTree tree1; private UITree tree; private TreeState treeState; @DataModel private List<Configuration> rNodes; @DataModel private List<Configuration> childNodes = null; public List<Configuration> getRootNodes() { if (rNodes == null) { System.out.println("In configTreeManager getrootNodes....."); rNodes = entityManager.createQuery( "from Configuration c where c.parentNodeId is null") .getResultList(); } return rNodes; } public List<Configuration> getChildren() { System.out.println("In configTreeManager getChildNodes....."); if (childNodes == null) { childNodes = entityManager.createQuery("from Configuration c") .getResultList(); } return childNodes; } private String name = ""; public String getName() { return name; } public void setName(final String name) { this.name = name; } }
*Data schema* Id NodeText ParentNodeId 1 node1 2 node2 3 node3 4 node4 5 node1a 1 6 node1b 1 7 node3a 3