Its very frequent requirement to implement Master-Detail relationships. Additionally it happens to render detail or master data for the same table, based on user selection. For example, we can have master screen with Locations data and another screen with detail data for Departments. But, if user opens Departments screen directly, it should bring complete list for Departments. So, complexity here - how to implement detail table for Departments data, with option to bring complete list of Departments as well.
This requirement can be solved mainly in three ways:
1. Duplicating Departments fragment - one for master and another for detail data
2. Implementing View Criteria to filter Departments conditionally
3. Implementing dynamic iterator binding and reusing View Link relationship
First option is highly not recommended, because it increasing number of fragments or pages - this means duplicating number of bugs. Second option is good and simple, however you need to declare View Criteria and filter View Object based on parameter. It works well, however we are not using built in ADF support for Master-Detail relationships. Third option - dynamic iterator binding works the best, because there is no need for View Criteria and we are reusing View Link functionality given by ADF.
Download sample application - DynamicIterator.zip. This sample implements a use case, where Departments data is rendered based on dynamic iterator declared in Page Definition.
As you can see from Data Control, we have two instances for Departments VO - DepartmentsMasterView and DepartmentsDetailView:
Controller layer implements Router activity, to open locations or departments fragments based on external parameter. If departments fragment will be opened directly, it should bring all departments:
In this sample, I'm mainly focusing on departments fragment and its Page Definition. Iterator for departments data:
Is binded to VO instance dynamically, using Expression Language. Based on page flow scope parameter, we set to use Master or Detail VO instance. Iterator binding is set dynamically:
Master and Detail instances for Departments VO:
Page flow scope parameter is set from Locations fragment:
Its value is initialized with Departments detail instance name - DepartmentsDetailView:
We can test it now, lets run our region with departments external parameter value, this will trigger conditional navigation in Router activity and will map master VO instance for departments iterator:
All departments are rendered by departments fragment:
We can navigate to Locations and select one of the locations, for example 1700:
Departments data is filtered now automatically, through View Link relationship implemented between Locations and Departments. This means, iterator for departments was initialized based on DepartmentsDetailView instance: