- Create a binding for treeTable in the backing bean.
- Add Two buttons For expand and collapse behaviors.
- Bind the button actionListeners to bean properties.
Use the below code in backing bean
public void expandAll(ActionEvent actionEvent) {
TreeModel model= (TreeModel) treeTable.getValue();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding ) model.getWrappedData();
ArrayList<JUCtrlHierNodeBinding> childList = (ArrayList<JUCtrlHierNodeBinding>)treeBinding.getChildren();
List newKeys = new ArrayList();
if(childList !=null){
for(JUCtrlHierNodeBinding node: childList){
newKeys.add(node.getKeyPath());
}
}
treeTable.getDisclosedRowKeys().addAll(newKeys);
AdfFacesContext.getCurrentInstance().addPartialTarget(treeTable);
}
public void collapseAll(ActionEvent actionEvent) {
treeTable.getDisclosedRowKeys().clear();
AdfFacesContext.getCurrentInstance().addPartialTarget(treeTable);
}
Note: Above code works for first level of node expansion, if you need to expand all levels you need to iterate to add all keypaths. Also the range size iterator needs to be set to -1 if you need all rows to be expanded, otherwise only the rows in the current range will be expanded.
Complete example can be downloaded here.
No comments:
Post a Comment