tree, expandAll, collapseAll issue
smith123 Mar 19, 2009 5:16 PMI have a tree with many nodes and it works perfectly fine.
Now since there are many nodes I have implemented expand all and collapse all feature using queueExpandAll(), queueCollapseAll().
I have two buttons expandAll, collapseAll to do this.
Here is the code:
@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.configUITree.queueExpandAll(); } catch (final Exception ex) { ex.printStackTrace(); if (logger.isDebugEnabled()) { logger.debug("IOException in Expand all Tree"); } } } public void collapseAll() { try { configUITree.queueCollapseAll(); } catch (final Exception ex) { ex.printStackTrace(); if (logger.isDebugEnabled()) { logger.debug("IOException in Collapse all Tree"); } } } } <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}" binding="#{configTreeComponentState.configUITree}"> <rich:recursiveTreeNodesAdaptor id="config" roots="#{configurationManager.rootNodes}" var="config" nodes="#{config.childrenNodes}" > <--- more code ----> </rich:recursiveTreeNodesAdaptor> </rich:tree> </h:form> </rich:panel>
What I notice is intially when the tree is loaded it sets the UITree in ConfigTreeComponentState and later when expandAll() is called the configUITree is null. Hence it throws a null pointer exception.
I was expecting to have the tree instance. How can I achieve the expandall, collapsall functionality.