Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label expand. Show all posts
Showing posts with label expand. Show all posts

Monday 21 October 2013

Expand and Collapse an af:treeTable programmatically in ADF Faces (Oracle ADF)

Hello all,
this is simple tutorial about expanding and collapsing an af:treeTable using managed bean code (programmatically)
sometimes we need to expand or collapse treeTable on some button action or on valueChangeEvent.


  • Create binding of treeTable in 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) {