Thursday, April 12, 2012

ADFBC - Dependent LOV with a create form.

Found that people are still having issues with creating dependent LOV and use the same to show up in create mode for the forms. Below steps describe the scenario devlopment and also given is the link to download the sample project.

Note: Development of the sample is using the pre-installed hr schema in the Oracle XE database, Using Jdev 11.1.2.x:

Step1: Create a new ADF application named 'ADFBCApp'.

Step2: Create the database connection (either using the Application overview that opens up on application creation or by using the new connection ) to the hr database schema.

Step3: Create the EO and ViewObjects for 'Countries' and the 'Locations' tables from the hr schema. Make sure when the EO and VO's get generated the App Module is checked so that the vO's get exposed as data controls.

Step4: Open the LocationsView.xml file which has got generated in the Model project if you have selected Model as the project during ADF BC generation.

Step5: Goto the Attributes tab. Select the CountryId attribute. Click on the List of Values tab and then click on the "+" sign. A wizard opens to configure the LOV. In the wizard now select the data source by clicking the "+" sign, that would be "CountriesView1"  and then select the  list attribute to be CountryId. In the UI Hint select the CountryName as the UI Hint to insure that the name of the country appears in the dropdown instead of the non user friendly "CountryId".

Step6:
Create a new view object for StatesViewLOV. This will be a SQL query view object, use the below given query to achieve the same.

SELECT distinct
    LOCATIONS.STATE_PROVINCE STATE_PROVINCE
FROM
    LOCATIONS
where country_id=:p_country
Also, add a bind variable to the SQL Query view object named p_country. It the same as the one used in the query.

Step 7:
Now open the LocationsView1.xml in Overview mode again. Navigate to the Attributes tab. Select StateProvince attribute. And add the LOV to the attribute as mentioned in step 5. But make sure you select StatesViewLOV instead of CountriesView1 as data source.

Step 8:
Now create a ADF bounded task flow (name it as task1) and a form1.jsff view file. Drag and drop the LocationView1 data control from the data control tab on the application navigator on the jsff page and select ADF form with submit button checked as the view component to be binded.

Step 9: For the CountryId select one choice component, in the Property inspector make the AutoSubmit property to be true. Then for the StateProvince field set the partial trigger attribute in property inspector to the CountryId field id (ex: soc2).

Step10: Now drag and drop the Create operation from the LocationsView -> Operations data control on the taskflow  diagram view. Then Drag and drop the jsff created. And link the two from Create operation to jsff using the ControlFlow component in the component palette. Keep the link event to be as it it. And save all the changes.

Step11:
Create a jspx page(name untitled1.jspx in the sample project) and then drag and drop the task1 taskflow from the Pageflows folder on the jspx page and select Region as the option for view binding.
Now run the untitled1.jspx page to see the Dependent LOV in create mode working.

Please use this link (ADFBCApp.zip) to download the sample project.