tree expandAll collapse issue
smith123 May 1, 2009 5:25 PMI had a similar post earlier but I don’t find the link to post anymore. Hence I am reposting this question. Please help me. I have a tree that displays large number of nodes. It’s working fine. Each time in order to navigate the nodes it’s tedious to expand each node. Hence in my design I have a button Expand All and Collapse All that must expand all the nodes on click of the button and collapse the tree nodes on click of collapse button.
I am struggling to get this work for long time, can anyone please help me, else we may have to forgo the rich tree. I have tried all the suggestion on the discussion forum. Help will be greatly appreciated.
In the code the component State is bound. How do we get the instance of the tree in order for the expand all collapse all function to work. Any time configUITree is always null when it comes to expandall function. Anywhere I can find the detail documentation apart from richfaces live demo site where I can dig in deeper to understand the behaviour of tree on how it is implemented.
Here is the code,
<rich:panel id="configtree" bodyClass="leftmenu_body_config"> <h:form> <div class="actionButtons" style="padding-bottom:10px"> <h:commandButton id="expand" styleClass="button" value="Expand" action="#{configTreeComponentState.expandAll}"/> <h:commandButton id="close" styleClass="button" value="Collapse" action="#{configTreeComponentState.collapseAll}" /> </div> <rich:tree switchType="ajax" stateAdvisor="#{treeStateAdvisor}" componentState="#{treeComponentState.componentState}"> <rich:recursiveTreeNodesAdaptor id="config" roots="#{configuration.rootNodes}" var="config" nodes="#{config.childrenNodes}" > <rich:treeNode> <h:outputText rendered="#{config.screen == null}" value="#{config.evalNodeText}"/> <s:link view="/#{config.screen.screenName}" rendered="#{config.screen != null}" propagation="none"/> </rich:treeNode> </rich:recursiveTreeNodesAdaptor> </rich:tree> </h:form> </rich:panel> </ui:composition> @Scope(ScopeType.SESSION) @Name("configTreeComponentState") public class ConfigTreeComponentState { private static Logger logger = Logger .getLogger(ConfigTreeComponentState.class); UITree configUITree; public final UITree getConfigUITree() { return configUITree; } public final void setConfigUITree(final UITree configUITree) { this.configUITree = configUITree; } public void expandAll() { try { //this.getConfigUITree(); configUITree..queueExpandAll(); } catch (final Exception ex) { ex.printStackTrace(); if (logger.isDebugEnabled()) { logger.debug("IOException in Expand all Tree"); } } } public void collapseAll() { try { //this.getConfigUITree(); configUITree.queueCollapseAll(); } catch (final Exception ex) { ex.printStackTrace(); if (logger.isDebugEnabled()) { logger.debug("IOException in Collapse all Tree"); } } } }