Expand and Collapse an af:treeTable programmatically in ADF Faces

Sharing is Caring

Hello all,
this is a simple tutorial about expanding and collapsing an af:treeTable using managed bean code (programmatically)
Sometimes we need to expand or collapse treeTable automatically on some button action or on valueChangeEvent without touching the treeTable icons, In that case, we can make use of component binding to do this in the managed bean itself.

Steps to expand and collapse ADF treeTable-

    • Create component binding of af:treeTable in the managed bean

 private RichTreeTable soTreeTableBind;
     public void setSoTreeTableBind(RichTreeTable soTreeTableBind) {
        this.soTreeTableBind = soTreeTableBind;

    public RichTreeTable getSoTreeTableBind() {
        return soTreeTableBind;


    • Now Call this method on any action to expand treeTable

private RowKeySet disclosedTreeRowKeySet = new RowKeySetImpl();

    /***Method to expand all tree table nodes*/
    private void expandTreeTable() {
        if (this.soTreeTableBind != null) {
            disclosedTreeRowKeySet = new RowKeySetImpl();
            CollectionModel model = (CollectionModel)soTreeTableBind.getValue();
            JUCtrlHierBinding treeBinding = (JUCtrlHierBinding)model.getWrappedData();
            JUCtrlHierNodeBinding rootNode = treeBinding.getRootNodeBinding();
            disclosedTreeRowKeySet = soTreeTableBind.getDisclosedRowKeys();
            if (disclosedTreeRowKeySet == null) {
                disclosedTreeRowKeySet = new RowKeySetImpl();
            List<JUCtrlHierNodeBinding> firstLevelChildren = rootNode.getChildren();
            for (JUCtrlHierNodeBinding node : firstLevelChildren) {
                ArrayList list = new ArrayList();
                expandTreeChildrenNode(soTreeTableBind, node, list);
/**Method to expand childs*/
    private void expandTreeChildrenNode(RichTreeTable rt, JUCtrlHierNodeBinding node, List<Key> parentRowKey) {
        ArrayList children = node.getChildren();
        List<Key> rowKey;
        if (children != null) {
            for (int i = 0; i < children.size(); i++) {
                rowKey = new ArrayList<Key>();
                if (((JUCtrlHierNodeBinding)(children.get(i))).getChildren() == null)
                expandTreeChildrenNode(rt, (JUCtrlHierNodeBinding)(node.getChildren().get(i)), rowKey);


    • To collapse treeTable, use this code snippet on any event

    /**Collapse TreeTable
     * @param actionEvent
    public void collapseTreeTableAction(ActionEvent actionEvent) {

Here is the list of packages used

import java.util.ArrayList;
import java.util.List;

import oracle.adf.view.rich.component.rich.data.RichTreeTable;

import oracle.jbo.Key;
import oracle.jbo.uicli.binding.JUCtrlHierBinding;
import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;

import org.apache.myfaces.trinidad.model.CollectionModel;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetImpl;


Cheers 🙂 Happy Learning

Related Posts

4 thoughts on “Expand and Collapse an af:treeTable programmatically in ADF Faces”

Leave a Reply

Your email address will not be published. Required fields are marked *