Understanding RowKey values in ADF TreeTable

For those working on ADF and using TreeTable or other Tabular components would have always wondered about this RowKey and lot of times many of the would have encountered the deadly NoSuchRowAvailable Exception.

  • In this post I will first develop a sample application using JDevelooper(11.1.2.1.0)which will create a treeTable and populate the data by stubbing some values into it.
  • Once we have a sample ready we can use it to understand the RowKeyIndex concept by using the rowKey values of the selected rows.

If you want to just know about the RowKeyIndex, then you can download the sample application from here and directly go to the Understanding RowKeyIndex section.

Creating the Sample Application

Basic skeleton application

The complete code can be downloaded from here.

  • Create a ADF Web Application in JDeveloper.
  • Select the “ViewController” project and create an Employee class in the view package – This will be our domain class.
  • In the sample project create a PageModel class TreeTablePageModel in the view.page package- This will hold the data for the page.
  • Populate the data for the page by stubbing the data in the PageModel constructor.
  • Register the PageModel class as a managed bean in the unbounded task-flow i.e in the adfc-config.xml at the view scope.
  • Create a new JSPX file- treeTable.jspx and switch to the code view in the IDE. (We developers are better at handling the code than playing around with the GUI)
  • Add a ADF TreeTable af:treeTable component and bind the data for the component. Also wrap the treeTable within a af:panelCollection.

Printing the rowKey on the page

In thie section we will look at capturing the rowKey of the selected row and print in it on the web page. The source code can be downloaded from here.

  • Add a af:outputText component below the treeTable to show the rowKey value of the selected row. We would have to play around with the layout a bit to get this showing up right.
  • Add a new property selectedRowKeyIndex in the managed bean to hold the rowKey of the selected row.
  • Create a View Bean class- TreeTableViewBean in the view.page package – This class will hold all the event handlers and client side activities of the JSPX.
  • Register the ViewBean class as a managed bean in the adfc-config.xml at the backingBean scope.
  • Create an event handler in the view bean and wire it up with the treeTable selectionListener attribute. This will listen to all the selection events.
  • Now we need to capture the RowKeyIndex of the selected row in the above event handler and then the rowKey value should be updated in the PageModel property.
  • The output text should register a partial trigger on the treeTable so that it can refresh itself when ever some event happens on the the treeTable.

After deploying the application, click on the treeTable row and see how the value in the outputText varies, also try with multiple selections.

Understanding the RowKeyIndex

Now that you have got an idea about the values for the selected row’s rowKey or for that matter any rowKey in a TreeTable, let me throw some light on the format and the rowKey values you see.

The rowKey is a list of list of integers- the outer most list is applicable when there are multiple rows being selected, in case of single row being selected the outer most list would always have only one value. The inner most list is something which is worth spending more time on. The inner most list is a list of integers using which one can traverse from the root node to the node which is selected.

Let me explain by taking more examples from the treeTable created above:
(Identifying the rows can be done as: the first part refers to “First Name” column and the second part refers to the “Last Name” column)
Selecting on “First Manager” would print: [[0]]
Selecting on “First Sub_1” would print: [[0,0]]
Selecting on “First Sub_2” would print: [[0,1]]
Selecting on “First Sub_3” would print: [[0,2]]
Selecting on “Sub_3 Sub_1” would print: [[0,2,0]]

Selecting on “Third Manager” would print: [[2]]
Selecting on “Third Sub_1” would print: [[2,0]]
Selecting on “Third Sub_2” would print: [[2,1]]
Selecting on “Third Sub_3” would print: [[2,2]]

Looking at the values above we see that

  • RowKey uses Zero based indexing.
  • Every parent will have zero based index associated with them.
  • And each child of the parent will have another zero based index associated with them.

So the effective rowKey of a selected row would be decided by traversing from the root till the selected node and noting the index of each node appearing in the traversal.

Now lets see how this value would vary when we do multiple selections. I will add the screenshot with the RowKeyIndex value printed in the outputText at the bottom of the treeTable.
TreeTable
Its important to know about RowKeyIndex because all the data idenfitication in the TreeTable/Tree/Table is done based on this RowKeyIndex value. In the future posts I will show you why you come across exceptions like “NoSuchRowAvailable” exception while dealing with refreshing the data in the TreeTable

If you want to play around with the code, please download the JDeveloper project and then run the application.

1 thought on “Understanding RowKey values in ADF TreeTable”

  1. Hi Mohamed. Your post is nice. But I want to know how can we get the values of the position [0,1] First Sub_2.

    Means outputtext will show only First Sub_2

    Can you help me in this.

    Reply

Leave a Reply

Discover more from Experiences Unlimited

Subscribe now to keep reading and get access to the full archive.

Continue reading