RF 4: rich:tree selectionChangeListener not invoked
mtle Apr 21, 2011 4:31 AMHi,
I'm using RF4 via maven with
<org.richfaces.bom.version>4.0.0.Final</org.richfaces.bom.version>
having trouble with the new rich:tree. The concept and the examples in the showcase look really simple (much better than in RF3), but it's not working for me. The tree is displayed, I can expand and collapse nodes, but the selection does not work.
Here is my xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <body> <ui:composition> <h:form prependId="false"> <rich:tree id="mBeanTree" value="#{treeBuilder.nodes}" var="node" toggleType="client" selectionType="ajax" selectionChangeListener="#{treeBean.processTreeSelectionChange}" nodeType="#{node.nodeType}"> <rich:treeNode type="SERVER" iconExpanded="/images/tree/server.png" iconCollapsed="/images/tree/server.png"> #{node.displayName}" </rich:treeNode> </rich:tree> </h:form> </ui:composition> </body> </html>
treeBean is sessionscoped and looks like this:
public class TreeBean implements Serializable, TreeSelectionChangeListener { private static final long serialVersionUID = 1L; private TreeNode currentSelection = null; public TreeNode getCurrentSelection() { return currentSelection; } public void setCurrentSelection(TreeNode currentSelection) { this.currentSelection = currentSelection; } /* (non-Javadoc) * @see org.richfaces.event.TreeSelectionChangeListener#processTreeSelectionChange(org.richfaces.event.TreeSelectionChangeEvent) */ public void processTreeSelectionChange(TreeSelectionChangeEvent selectionChangeEvent) throws AbortProcessingException { System.out.println("change"); // considering only single selection List<Object> selection = new ArrayList<Object>(selectionChangeEvent.getNewSelection()); Object currentSelectionKey = selection.get(0); UITree tree = (UITree) selectionChangeEvent.getSource(); Object storedKey = tree.getRowKey(); tree.setRowKey(currentSelectionKey); currentSelection = (TreeNode) tree.getRowData(); tree.setRowKey(storedKey); } }
I also tried it with TreeBean not implementing TreeSelectionChangeListener - not working either.
The processTreeSelectionChange method is not invoked and the selcted node is not marked as selected (gray background). However, if I change selectionType of the rich:tree from ajax to client, the visual selection works (gray background) but the processTreeSelectionChange method is still not invoked.
Does anybody have an idea whats wrong?
Many thanks in advance!
And by the way: The documentation says, that the selectionType attribute can also be "server", but this leads to an illegal argument exception.