Some times when we want to display some master detail data we use an af:tree because it is a easy and elegant way to display data. I am going to show you how to display data of the selected node in an af:tree based on a single view object.
We are going to use this data model based on Oracle hr schema.
The first thing we have to do is drag and drop the EmployeesView1 view object from the data control palette to the page.
After that we also have to add a form based on EmployeesView. Here is the problem. What view object instance are we going to use to create the form? If we use Parent instance, although we select a child node, in the form we are going to see just the parent node data.
In order to solve this issue we are going to create a new instance of the Employees view object, in this case EmployeesDisplayVO.
The next step is to create a Action Binding with setCurrentRowWithKey operation of the new view object instance in the pagedef of our page.
The last step is to create a custom Selection Listener in our bean and associate it to the af:tree
In this method, a part from ejecute makeCurrent method of the treeModel, we are going to get selected keys and execute setCurrentRowWithKey method with the selected key as parameter.
When we select the first node only one key is in the list, but if we select the second or third level we will have one key per level and we will have to use keyList.get(keyList.size() – 1) in order to get the last selected key.
If we run again the application we can se that if we select any node we can see its information in the form.