Skip to main content

Programmatically disclosing nodes in a <af:tree>

Programmatically disclosing nodes in a <af:tree> is a very common use case in Rich Inernet Applications. I'm sharing an example (built using ADf Faces) illustrating three different use cases on this topic.

1. Expand all nodes of a <af:tree> component
2. Collapse all nodes of <af:tree> component
3. Expand specific nodes of <af:tree> component


Download

You can download the sample workspace from here.
[Runs with Oracle JDeveloper 11g R1 PS3 + HR Schema]

A glance at the implementation

1. Expand all nodes of a <af:tree>

This disclosed behavior of a tree component is controlled by the DisclosedRowKeys of tree component. The below shown method make use of constructor RowKeySetTreeImpl(boolean addAll) to create instance of RowKeySet having all rowKeys added. Please note that, if the parameter 'addAll' is true, every rowKey is initially added to this RowKeySet. This effectively would result in disclosure of all nodes when the tree is displayed.

 public void expandAllTreeNodes(ActionEvent act) {  
   
  UIXTree tree = getTree();  
  RowKeySet _disclosedRowKeys = new RowKeySetTreeImpl(true);  
  _disclosedRowKeys.setCollectionModel(ModelUtils.toTreeModel(tree.getValue()));  
  tree.setDisclosedRowKeys(_disclosedRowKeys);  
   
 }    

2. Collapse all nodes of <af:tree> component

This is achieved by clearing off the DisclosedRowKeys of the tree component.

   
 public void collapseAllTreeNodes(ActionEvent act) {  
   
  UIXTree tree = getTree();  
  RowKeySet _disclosedRowKeys = tree.getDisclosedRowKeys();  
  if (_disclosedRowKeys != null && _disclosedRowKeys.size() > 0) {  
   _disclosedRowKeys.clear();  
  }  
  tree.setDisclosedRowKeys(_disclosedRowKeys);  
    
 }  

3. Expand specific nodes of <af:tree> component

The code searches for a specific node value by setting the Rowkey to an indexed value and iterate over nodes recursively.
Fusion Web UI Developers Guide Says:
The tree model is a collection of rows. It has an isContainer() method that returns true if the current row contains child rows. To access the children of the current row, you call the enterContainer() method. Calling this method results in the TreeModel instance changing to become a collection of the child rows. To revert back up to the parent collection, you call the exitContainer() method.

Comments

subu said…
This comment has been removed by the author.
subu said…
nice post,
in same tense.
i had some usecase. i cant achieve it.
you may give right direction.
here my usecase regards af:tree with links navigating to the page

>> configuration
|
>config1010 basicemployeeprofile
>config1020 salaryprofile
>> transaction
|
>trans1010 profile
>trans1020 salaryupdation

no problem with this tree.
my concept is simple.

when i click config1010 means it want to navigate to
config1010.jspx page or jsff.

when i click config1020 means it want to navigate to
config1020.jspx page or jsff.

here n most example, which i saw is , when i click the node means navigate to corresponding records.

here i want to navigate corresponding page.

so thing is simple the id that is config1010.
if config1010 is clicked means
navigate config1010.jspx page
This comment has been removed by the author.
no neo said…
thank you very much.
good code
Thank you.
This was very helpful for me.

Popular posts from this blog

How to set Bind Variable Values at runtime ?

In this post I'm sharing a couple of approaches for programmatically setting bind variables values at run time. This post is an attempt to explain 'When to use what ?'[ In case if you are familiar with 'Bind Variables' in ADF BC, please refer Section 5.10, Working with Bind Variables in Fusion Developer's Guide ]

1. Set the Bind Variable value using RowSet::setNamedWhereClauseParam(...)

You can use use the setNamedWhereClauseParam(...) method on the ViewObject interface (which extends oracle.jbo.RowSet) to set the value for bind variables. Please note this sets the value on default RowSet. In other words, this doesn't have any effect on the secondary RowSets that you/system generates.
ViewObject vo = am.findViewObject("EmployeesView1"); vo.setNamedWhereClauseParam("bindVarDeptId", new Number(10)); vo.executeQuery();
2. Set the Bind Variable value using ViewObject's VariableValueManager::setVariableValue(...)

VariableValueManager Ma…