Selecting a node on an ADF Tree control sets the current record in a different data source
By Grant Ronald-Oracle on Oct 20, 2010
While doing some redevelopment of a Forms application in ADF the following use case came up. The user is able to view a tree which shows either SalesReps and their customers, or, Countries and their Customers. So, how could I implement this in ADF?
The key was that, in my mind, the data model was something like this:
Countries or SalesReps
At first I thought that in the application module I might have two hierarchies. One with Countries as the top node, and another with SalesReps as the top node. However, there was a different way:
I created the data model to look like this:
Here you can see that Countries and Emps (SalesReps) are at the top level but so is Customers.
I then created my page to look something like this:
The key point was that the tree control didn't need the data model to physically be Countries (or SalesReps) and then Customers as a detail of that. So long as there was a view link accessor from Countries to Customers (and the same for SalesReps to Customers) then the tree control could make use of that.
So the next step, on selecting a node in the tree, how could I synch that to the form on the right of the page which was bound to the Customers data control? Well it turns out ADF makes this easy. If you go to the binding for the tree control you will see the following:
The point to note is Target Data Source which points to the Customers iterator. This means that on selecting the tree node, the tree will force an update of the Customers iterator. The only other thing you need to do is set PPR so the page updates correctly.
So you get: