rich:tree value attribute does not work
timgrant Feb 19, 2008 9:54 AMI am using the value attribute of a rich:tree control to hold the tree's selection across page transitions. Consider this template code:
<h:form id="myIndex">
<rich:tree
id="folderList"
showConnectingLines="false"
switchType="ajax"
toggleOnClick="true"
value="#{myMenuController.currentSelection}">
<rich:recursiveTreeNodesAdaptor
roots="#{myMenuController.sourceRoots}"
nodes="#{item.directories}"
var="item">
<rich:treeNode>
<h:commandLink
action="#{mySearchController.showFiles( item )}"
value="#{item.name}" />
</rich:treeNode>
</rich:recursiveTreeNodesAdaptor>
</rich:tree>
</h:form>
And this controller code:
@Name( "myMenuController" )
@Scope( ScopeType.SESSION )
public class MyMenuController implements Serializable {
private final DocumentIndexModel model;
private TreeNode currentSelection;
@Out
private final List<FileSystemNode> sourceRoots;
@Logger
private Log logger;
public MyMenuController() {
model = new DocumentIndexModel();
sourceRoots = model.getSourceRoots();
}
public TreeNode getCurrentSelection() {
logger.debug( "getCurrentSelection() = " + currentSelection );
return currentSelection;
}
public void setCurrentSelection( TreeNode currentSelection ) {
logger.debug( "setCurrentSelection( " + currentSelection + " )" );
this.currentSelection = currentSelection;
}
public List<FileSystemNode> getSourceRoots() {
return sourceRoots;
}
}
@Name( "mySearchController" )
@Scope( ScopeType.SESSION )
public class BusdocsSearchController {
@Logger
private Log logger;
@Out( required = false )
private List<FileSystemNode> searchResults;
@Out( required = false )
private String shortPath;
public String showFiles( FileSystemNode node ) {
logger.debug( "showFiles( " + node.getPath() + " )" );
shortPath = node.getKey();
searchResults = node.getFiles();
return "showFiles";
}
public String getShortPath() {
return shortPath;
}
public List<FileSystemNode> getSearchResults() {
return searchResults;
}
}
finally, pages.xml:
<page view-id="/view/main.xhtml"> <navigation> <rule if-outcome="showFiles"> <redirect view-id="/view/folder_view.xhtml" /> </rule> </navigation> </page>
Both main.xhtml and folder_view.xhtml use the same tree control.
I can see in the log where getCurrentSelection() is called, returning a null value; however, setCurrentSelection() is never called. The problem is that when I select a node, control is passed to the folder_view page and my tree selection is lost.
This method is working well for a rich:panelBar in the same template code. Everything else about the application works well, I only cannot keep the tree selection intact.
Any suggestions as to how I can keep the tree selection?
Thanks,
Tim