Developer Tools
JDeveloper
Building Cascading Lists for Query Screens with ADF Business Components & JSP
Written by Duncan Mills, Oracle Corporation
July 2004
Introduction
For web deployed applications it is common to provide query screens or search areas that allow the user to both query by example and select options from drop down lists to restrict the query results. A requirement that often comes up is to drive such lists from lookup tables in the database and additionally where there is a relationship between reference data elements, automatically narrow detail lists based on the selection in a master list. In this case I'll show an example with two drop down lists driven from the REGIONS and COUNTRIES tables in the standard Oracle HR schema. The idea here is that we can use these linked list items to select a particular country. When the region is selected in the first list, then the second list automatically displays just the countries in that region.
The approach here can be emulated to any depth, with any tables as long as they have view links set up between them, and the nice feature is that we don't have to write any of the list coordination code, the ADF Business Components framework does all of that work for us.
The Technique
There are several ways that this kind of interdependent list user interface can be driven, and different approaches have different advantages. It is, for instance, common in traditional web applications to use a JavaScript based solution where the whole dataset (master list and all detail lists) is downloaded into the browser and then JavaScript is used within the page to coordinate the lists. This technique has the advantage of not requiring further round trips during list operation, but of course you pay the penalty in downloading all of that data in the first place, irrespective of if you need it or not.
So the solution outlined here, actually goes back to the middle tier when each selection on the master list is made, however, it does have the benefit of being able to operate in a browser that has JavaScript disabled.
The technique itself depends on two things:
Setting Up the Data Model
The first step to carry out is to define the View Objects (VO) and View Links(VO) used to define the data for driving the lists. I'd recommend that you define totally separate View Objects for use in the lists rather than trying to reuse and existing one. The reason for this, is that we will be changing the record currency as the lists are used, and this could have undesired side effects if reusing an existing VO.
Assuming the use of the Regions and Countries tables from the HR Schema and that you already have Entity Objects for both of those tables.
Creating the Basic Search Screen
What Next?
So far we simply have two interrelated drop down lists, what you need to do next is to be able to extract some information from them - in this case you care probably interested in the COUNTRY_ID defined by the user's final selection. To make this value available in the binding context, the simplest approach will be to expand the CountriesList View Object in the Data Control Palette, select the CountryId attribute and drag and drop that as a "Value" into the page. This will create the relevant value bindings for you and a <c:out> tag to print the current CountryId on the screen. You can delete the <c:out> tag unless you want to see it for debugging purposes. Now, when a new country is selected in the country list box the expression ${data.searchScreenUIModel.CountryId} will provide the current country selection for use in passing to DataAction parameters. (Note the name of the UIModel will differ depending on what you called your initial DataPage). So if you have created a search DataAction you can simply pass the selected country Id to it.
Restrictions
where exists
(select null from COUNTRIES C
where C.REGION_ID = Regions.REGION_ID
and exists
(select null from LOCATIONS L
where L.COUNTRY_ID = C.COUNTRY_ID))
drmills v1.1