Please disable your adblock and script blockers to view this page

Search this blog

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.

Steps-

  • 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();
                    list.add(node.getRowKey());
                    disclosedTreeRowKeySet.add(list);
                    expandTreeChildrenNode(soTreeTableBind, node, list);
                }
                soTreeTableBind.setDisclosedRowKeys(disclosedTreeRowKeySet);
            }
        }
    /**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>();
                    rowKey.addAll(parentRowKey);
                    rowKey.add(((JUCtrlHierNodeBinding)children.get(i)).getRowKey());
                    disclosedTreeRowKeySet.add(rowKey);
                    if (((JUCtrlHierNodeBinding)(children.get(i))).getChildren() == null)
                        continue;
                    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) {
            soTreeTableBind.getDisclosedRowKeys().clear();
            AdfFacesContext.getCurrentInstance().addPartialTarget(soTreeTableBind);
        }
    

No comments :

Post a Comment