You could use ChangeExpandListener
The <rich:changeExpandListener>
represents an action listener method that is notified on an expand/collapse event on the node.
EDIT:
First changeExpandListener has to be delared as attribute for <rich:treeNode>
, if is declared for entired tree works as you write (event is processed after selection event).
So:
<rich:tree value="#{simpleTreeBean.treeNode}" var="item" >
<rich:treeNode changeExpandListener="#{simpleTreeBean.processExpansion}">
<h:outputText value="#{item}" />
</rich:treeNode>
</rich:tree>
processExpansion method must take NodeExpandedEvent as a parameter but there is no need to implement interface org.richfaces.event.NodeExpandedListener.
public void processExpansion(NodeExpandedEvent evt) {
Object source = evt.getSource();
if (source instanceof HtmlTreeNode) {
UITree tree = ((HtmlTreeNode) source).getUITree();
if (tree == null) {
return;
}
// get the row key i.e. id of the given node.
Object rowKey = tree.getRowKey();
// get the model node of this node.
TreeRowKey key = (TreeRowKey) tree.getRowKey();
TreeState state = (TreeState) tree.getComponentState();
if (state.isExpanded(key)) {
System.out.println(rowKey + " - expanded");
} else {
System.out.println(rowKey + " - collapsed");
}
}
}
That's should help