I have had the problem to get node data from a richfaces tree, if the user selects a node. I have used a recursive tree adapter:
<rich:tree switchType="server"
stateAdvisor="#{treeStateAdvisor}"
nodeSelectListener="#{treeMgrt.onSelect}">
<rich:recursiveTreeNodesAdaptor roots="#{treeMgrt.roots}" var="item" nodes=" {item.nodes}">
<rich:treeNode>
<h:outputText value="#{item}"/>
</rich:treeNode>
</rich:recursiveTreeNodesAdaptor>
</rich:tree>
The method in my tree manager onSelect(…) looks like this:
public void onSelect(final NodeSelectedEvent event) {
final UITree theTree = this.getTree(event);
if (null == theTree) {
return;
}
final Object rowKey = theTree.getRowKey();
// this works better
final Object rowData = theTree.getRowData(rowKey);
if (rowData instanceof ProductNode) {
this.selectedNode = (ProductNode) rowData;
}
}
Normally you can use theTree.getTreeNode(); but with a recursive tree model which method returns alway null. Instead of this I have used the getRowData() method which works for me.
I have filed a bug for richfaces. Hope the problem becomes shortly a solution.