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.
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
- Now Call this method on any action to expand treeTable
- To collapse treeTable ,use this code snippet on any event
private RichTreeTable soTreeTableBind; public void setSoTreeTableBind(RichTreeTable soTreeTableBind) { this.soTreeTableBind = soTreeTableBind; } public RichTreeTable getSoTreeTableBind() { return soTreeTableBind; }
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); } } }
/**Collapse TreeTable * @param actionEvent */ public void collapseTreeTableAction(ActionEvent actionEvent) { soTreeTableBind.getDisclosedRowKeys().clear(); AdfFacesContext.getCurrentInstance().addPartialTarget(soTreeTableBind); }