-
1. How to keep rich:tree component state?
kanal Feb 24, 2011 2:27 AM (in response to kanal)After downloading milestone 6 i have checked the packages and there is still no TreeState class in there.
Has the class name changed or maybe there's another way to keep rich:tree component state between navigating through pages?
-
2. How to keep rich:tree component state?
nbelaevski Feb 24, 2011 6:45 PM (in response to kanal)Hi Paul,
In RF4 you should bind 'expanded' and 'selection' to model beans explicitly using EL-expressions.
-
3. How to keep rich:tree component state?
kanal Feb 28, 2011 6:03 AM (in response to nbelaevski)Hi Nick,
Could you give me a simple example on how to use these attributes?
-
4. Re: How to keep rich:tree component state?
burkatzkim Mar 4, 2011 6:27 AM (in response to kanal)I have also problems to keep the state with rich:tree and I would highly appreciate an example.
Maybe it is a good idea to integrate this example with the richfaces showcase? Thank you very much in advance.
-
5. Re: How to keep rich:tree component state?
ilya_shaikovsky Mar 4, 2011 8:02 AM (in response to burkatzkim)sorry guys.. too much on the team plates prior to Final. so have only simple samples where selection is get from selection change event.
and filled https://issues.jboss.org/browse/RF-10701 for specific demo.
-
6. Re: How to keep rich:tree component state?
abdeslam_nasri Aug 2, 2011 4:02 AM (in response to ilya_shaikovsky)I faced the same problem with refresh instability of rich:tree. I share with you so that may help anyway.
My solution goes deep in reconsidernig the coding of some core java classes in richfaces UI components. Mainly 2 classes AbstractTree.java and TreeRange.java in the package org.richfaces.component had to change. I also added an interface NodeExpansionState that should be implemented by the variable that holds the tree state in the session bean. I attach the sources to this reply.
First, define the tree node class used by loadTree() method, for example:
public class NamedNode extends DefaultMutableTreeNode implements NodeExpansionState { protected String type; protected String name; protected boolean expanded =false; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public String toString() { return this.name; } public boolean isExpanded() { return expanded; } public void setExpanded(boolean expanded) { this.expanded = expanded; } }
In the jsf page where you define your tree:
<rich:tree id="tree" var="node" keepSaved="true" stateVar="treeState" toggleType="ajax" value="#{treeBean.rootNodes}" selectionType="ajax" nodeType="#{node.type}" toggleListener="#{treeBean.toggleNodeListener}"> <rich:treeNode > #{node.name} </rich:treeNode> </rich:tree>
In your session bean, define the toggle listener:
@ManagedBean @SessionScoped public class TreeBean implements Serializable { private List<TreeNode> rootNodes = new ArrayList<TreeNode>(); ..... public void toggleNodeListener(TreeToggleEvent ev){ UITree tree = (UITree)ev.getSource(); NodeExpansionState nodeExp = ((NodeExpansionState)tree.getRowData()); nodeExp.setExpanded(!nodeExp.isExpanded()); } }
You can even decide to set some nodes expanded by default by simply set Expanded to true when you create the tree in addNodes(...) method.
-
richfaces_component_ui.zip 30.7 KB
-