Is there an event to collapse rich: tree node?
I was finally able to get events if the user expands a node of the client-side handled tree using the following method:
public void processExpansion(NodeExpandedEvent event) throws AbortProcessingException {
if (event != null && event.getSource() != null && event.getSource() instanceof HtmlTree) {
this.expandedNodes.add(((UITree) event.getSource()).getRowData());
}
}
I had to use #getRowData () because of recursiveTreeNodesAdaptor.
How can I get notified of nodes that the user is crashing again? I could not find a suitable listener.
source to share
You can use ChangeExpandListener
<rich:changeExpandListener>
is an action listener method that is notified of an expand / collapse event on a node.
EDIT:
The first change is the ExpandListener must be declared as an attribute for <rich:treeNode>
if declared for a managed tree as you write (the event is handled after the select event). So:
<rich:tree value="#{simpleTreeBean.treeNode}" var="item" >
<rich:treeNode changeExpandListener="#{simpleTreeBean.processExpansion}">
<h:outputText value="#{item}" />
</rich:treeNode>
</rich:tree>
The processExpansion method must accept a NodeExpandedEvent as a parameter, but there is no need to implement the org.richfaces.event.NodeExpandedListener interface.
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");
}
}
}
This should help
source to share