This content has been marked as final. 
    
Show                 5 replies
    
- 
        1. Re: rich:tree to be expanded by defaultnbelaevski Aug 18, 2009 12:43 PM (in response to sait)Hi, 
 Use tree state advisors - see livedemo examples and docs for more.
- 
        2. Re: rich:tree to be expanded by defaultsait Aug 18, 2009 12:58 PM (in response to sait)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 defaultnbelaevski Aug 18, 2009 6:09 PM (in response to sait)Sure, check livedemo example for treeNodeAdaptor. Several levels are initially expanded there. 
- 
        4. Re: rich:tree to be expanded by defaultsait Aug 19, 2009 2:05 AM (in response to sait)TreeDemoStateAdvisor.java import org.richfaces.component.UITree; import org.richfaces.component.state.TreeStateAdvisor; import org.richfaces.model.TreeRowKey; import org.jboss.seam.annotations.Name; @Name("treeDemoStateAdvisor") 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; } }
 PostbackPhaseListener.javaimport 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 .getName(); 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( POSTBACK_ATTRIBUTE_NAME)); } } return false; } }
 XHTML code<rich:tree style="width:300px" switchType="ajax" stateAdvisor="#{treeDemoStateAdvisor}"> <rich:recursiveTreeNodesAdaptor roots="#{fileSystemBean.sourceRoots}" var="item" nodes="#{item.nodes}" /> </rich:tree>
 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 defaultuser1234 Aug 19, 2009 7:32 AM (in response to sait)From the constructor of your class, call the method 
 public void changeOpenNode() {
 try {
 tree.queueExpandAll();
 } catch (IOException e) {
 }
 }
 Here variable "tree" is binded with your rich:tree
 <rich:tree binding="bean.tree" ...>
 
     
    