-
1. Re: rich:tree expand all TreeNodes
fmarwede Nov 4, 2007 6:06 AM (in response to jak.wei)There are more than one possibilities I think.
First I tried to use a component binding for the whole tree and then the method queueExpandAll(). But here I got an exception (no parent) I don't understand. Perhaps somebody else can help here.
Second I tried a method binding with the adviseNodeOpened attribute and this works. Here a little bit of code:
In your jsp/xhtml:<rich:tree ... adviseNodeOpened="#{bean.nodeOpened}" ... > ... </rich:tree>
In your bean:public Boolean nodeOpened(UITree tree) { if (expandAll) { return Boolean.TRUE } return null; }
Now you only have to make sure that the boolean 'expandAll' is initially set to true and after loading the page set to false. Otherwise your tree stays completely open whatever you click. -
2. Re: rich:tree expand all TreeNodes
domelq Dec 5, 2007 3:38 PM (in response to jak.wei)Hi know that its late answer but you can also do it on client side
function collapseAll() { var tree = window['Richfaces_Tree_tree_tree']; var childs = tree.childs; collapse(childs); } function expandAll(){ var tree = window['Richfaces_Tree_tree_tree']; var childs = tree.childs; expand(childs); } function collapse(childs) { for (var i = 0; i < childs.length; i++) { var element = childs; var cc = element.childs; if (cc.length != 0) { if (!element.isCollapsed()){ collapse(cc); element.eventCollapsionClick(); } } } } function expand(childs) { for (var i = 0; i < childs.length; i++) { var element = childs; var cc = element.childs; if (cc.length != 0) { if (element.isCollapsed){ element.eventCollapsionClick(); expand(cc); } } } }
Just change the name of tree (probably somehow you could get it from varState) -
3. Re: rich:tree expand all TreeNodes
bm97 Jan 31, 2008 11:04 AM (in response to jak.wei)You can use
UITree.queueExpandAll()
from java code.
See http://labs.jboss.com/auth/wiki/en/ExpandCollapseTreeNodes -
4. Re: rich:tree expand all TreeNodes
vh Jan 31, 2008 3:11 PM (in response to jak.wei)Is there any way to make the tree expand at the first time it renders? With out use .js or going back to server to call UITree.queueExpandAll()?
-
5. Re: rich:tree expand all TreeNodes
bm97 Feb 1, 2008 3:58 AM (in response to jak.wei)@vh: The code from fmarwede (second post) should do the job.
-
6. Re: rich:tree expand all TreeNodes
nbelaevski Feb 1, 2008 3:25 PM (in response to jak.wei)Please see the similar problem solved in richfaces-demo (see recursiveTreeNodesAdaptor demo). PhaseListener is used there.
-
7. Re: rich:tree expand all TreeNodes
pdpantages Mar 10, 2008 10:07 PM (in response to jak.wei)Hello Forum,
I am using richfaces packaged with Seam 2.0.1.GA
I also want to expand a tree the first time it renders. My needs are slightly different: I keep my tree in SESSION scope and it can be shared by several pages if the operator
is inclined to open up a few tabs.
The "postback check" in the richfaces demo will re-apply the policy on my tree whenever a new tab is opened, which I don't really want.
I have also found that tree.getParent() returns null the first time the tree is bound to my backing bean. This prevents me from calling queueExpandAll() as the latter throws an illegalArgument exception when the parent is null. The binding occurs before TreeStateAdvisor.adviseNodeOpened() is called. I noticed that the parent is no longer null when adviseNodeOpened() is called.
But in subsequent bindings, the parent is not null. Even if the user re-refreshed pages, or opens tabs etc.
So, my question is, this behaviour (the null value returned by getParent(), first time ) normal/expected, or a bug? I want to use this to control my TreeStateAdvisor, but am a bit hesitant to rely on such a thing....
I can set a flag in my TreeStateAdvisor, to tell it not to do the expansion once the tree has been established. This seems to work OK.
My tree is setup like so:<rich:tree switchType="ajax" stateAdvisor="#{subnetTreeImpl.subnetTreeStateAdvisor}" binding="#{subnetTreeImpl.nodeTableTree}"> <rich:recursiveTreeNodesAdaptor roots="#{treeData}" var="node" nodes="#{node.children}" > ....
My TreeStateAdvisorpackage centina.sa.client.utils; import org.richfaces.component.UITree; import org.richfaces.component.state.TreeStateAdvisor; import org.richfaces.model.TreeRowKey; // Based on the examples from richfaces demo org/richfaces/treemodeladaptor public class SubnetTreeStateAdvisor implements TreeStateAdvisor { public SubnetTreeStateAdvisor() { this.depth = 1 ; this.isTreeBound = false; } public Boolean adviseNodeOpened(UITree tree) { if ( ! this.isTreeBound ) { Object key = tree.getRowKey(); TreeRowKey treeRowKey = (TreeRowKey) key; if (treeRowKey == null ) { return Boolean.TRUE; } else if (treeRowKey.depth() <= this.depth) { return Boolean.TRUE; } } return null; } public Boolean adviseNodeSelected(UITree tree) { return null; } // Set the initial expansion depth of the tree. // Set to 0 to collapse. public int depth; public int getDepth() { return this.depth; } public void setDepth( int depth ) { this.depth = depth; } // This flag is used to disable the initial "advice" // once the subnetTree has been bound. Thus we don't // override the operator's discretion if he collapses the tree // after its initial rendering. // Normally, opening a new tab or re-rendering the page using // the top menu would cause the tree to be re-expanded up to the // "depth" setting. private boolean isTreeBound; public boolean getIsTreeBound() { return this.isTreeBound; } public void setIsTreeBound( boolean isTreeBound ) { this.isTreeBound = isTreeBound; } }
-
8. Re: rich:tree expand all TreeNodes
temujin Aug 9, 2012 3:43 AM (in response to pdpantages)I am using richfaces-components-ui-4.2.2.Final version. which dodn't contain
TreeStateAdvisor class, How can i make default expand tree.
-
9. Re: rich:tree expand all TreeNodes
mjuriscimjurisic Jan 16, 2014 5:22 AM (in response to temujin)Hi,
<rich:treeNode expanded="#{true}"> has done the trick for me.
Maybe it saves few minutes for somebody else.
Regards,
Marko