5 Replies Latest reply on Aug 19, 2009 7:32 AM by Deb Dutta

    rich:tree to be expanded by default

    Mustafa Sait Ozen Newbie


      Any ideas on how to have all nodes of rich:tree to be expanded by default?

      Thanx in advance

        • 1. Re: rich:tree to be expanded by default
          Nick Belaevski Master


          Use tree state advisors - see livedemo examples and docs for more.

          • 2. Re: rich:tree to be expanded by default
            Mustafa Sait Ozen Newbie

            The reason why I am writing on this forum is that I have exactly researched the things you suggested but I could not find clear and actual solution to "rich:tree to be expanded by default" problem.

            You suggested to use tree state advisors. Is there a clear example using tree state advisors to solve this solution ??

            • 3. Re: rich:tree to be expanded by default
              Nick Belaevski Master

              Sure, check livedemo example for treeNodeAdaptor. Several levels are initially expanded there.

              • 4. Re: rich:tree to be expanded by default
                Mustafa Sait Ozen Newbie


                import org.richfaces.component.UITree;
                import org.richfaces.component.state.TreeStateAdvisor;
                import org.richfaces.model.TreeRowKey;
                import org.jboss.seam.annotations.Name;
                public class TreeDemoStateAdvisor implements TreeStateAdvisor {
                 public Boolean adviseNodeOpened(UITree tree) {
                 if (!PostbackPhaseListener.isPostback()) {
                 Object key = tree.getRowKey();
                 TreeRowKey treeRowKey = (TreeRowKey) key;
                 if (treeRowKey == null || treeRowKey.depth() <= 2) {
                 return Boolean.TRUE;
                 return null;
                 public Boolean adviseNodeSelected(UITree tree) {
                 return null;


                import java.util.Map;
                import javax.faces.context.ExternalContext;
                import javax.faces.context.FacesContext;
                import javax.faces.event.PhaseEvent;
                import javax.faces.event.PhaseId;
                import javax.faces.event.PhaseListener;
                public class PostbackPhaseListener implements PhaseListener {
                 public static final String POSTBACK_ATTRIBUTE_NAME = PostbackPhaseListener.class
                 public void afterPhase(PhaseEvent event) {
                 public void beforePhase(PhaseEvent event) {
                 FacesContext facesContext = event.getFacesContext();
                 Map requestMap = facesContext.getExternalContext().getRequestMap();
                 requestMap.put(POSTBACK_ATTRIBUTE_NAME, Boolean.TRUE);
                 public PhaseId getPhaseId() {
                 return PhaseId.APPLY_REQUEST_VALUES;
                 public static boolean isPostback() {
                 FacesContext facesContext = FacesContext.getCurrentInstance();
                 if (facesContext != null) {
                 ExternalContext externalContext = facesContext.getExternalContext();
                 if (externalContext != null) {
                 return Boolean.TRUE.equals(externalContext.getRequestMap().get(
                 return false;

                XHTML code

                <rich:tree style="width:300px" switchType="ajax" stateAdvisor="#{treeDemoStateAdvisor}">
                 <rich:recursiveTreeNodesAdaptor roots="#{fileSystemBean.sourceRoots}" var="item" nodes="#{item.nodes}" />

                To keep tree state between pages use solution at http://seamframework.org/Community/ProblemToKeepRichtreeState

                Mustafa Sait ÖZEN

                • 5. Re: rich:tree to be expanded by default
                  Deb Dutta Novice

                  From the constructor of your class, call the method

                  public void changeOpenNode() {
                  try {
                  } catch (IOException e) {


                  Here variable "tree" is binded with your rich:tree

                  <rich:tree binding="bean.tree" ...>