Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file)

In a recent article I gave a brief introduction of the ADF 11g Placeholder Data Control – see: ADF 11g Placeholder Data Control – for off line demonstration of application and/or rapid UI prototyping without a need for a business service – and the value of using that type of Data Control for User Interface design/prototyping. I promised to take a closer look at same slightly more interesting aspects of this type of data control. How the data control can be created from a CSV file – both attributes and sample data-, how Placeholder Data Control Data Types can have a master details relationship and how an ADF Faces component, bound to a Placeholder Data Control can be rebound to another Data Control. ....

First of all, say we have two CSV files – depts.csv and emp.csv – that contain the off line data from the DEPT and EMP table I frequently use for demonstrations. Note: these csv files can be created in a number of ways, including the data export functionality in SQL Developer, APEX, TOAD or PL/SQL Developer.

Now when we create a new Data Type under a Placeholder Data Control, instead of creating attributes and entering sample data manually, we have JDeveloper do the work for us.

Create a Data Type from the context menu on the Data Control

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc015 

Type in a name. Remove the Attribute by default created

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc016

Go to the Sample Data tab. Press Import. Select the dept.csv file.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc017

Now the Department Data Type shows up. Select it and from the context menu select the option to Create a Data Type. This latter data type will be a child of the Department. Call the new Data Type Employee.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc018

The first Attribute of Department – Deptno – is already created in the new Data Type. This attribute will implement the Foreign Key to the Master.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc019 

Manually define all other attributes available in the CVS file to load. Note that Deptno must be the first field in the records in the CVS file.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc020

Make sure that the data in the CSV file is in the same order as these attributes.

Go to the Sample Data tab and select the Employee.cvs file. The data is read from this file:

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc021

 In the Data Controls Palette, we now have Employee as a detail for Department.

 

 Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc022

 We can now drag the Employee Data Type to a new JSF page, and drop it as ADF Master Form, Detail Table.

 Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc023

 In the design time, this results in:

 

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc024

When we run the page, we run into an issue: the page structure is fine, however: no data is actually presented. I can find that the number of Dept records is four. The number of child rows is constant at 14. Even though data is not shown, the records still are there, all the same. However, proof of Placeholder’s Data Control Master-Detail capabilities is not yet available.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc025

While this is slightly disappointing, I suppose it is a pre-production bug. When I drop the Department as a ADF Read Only Forms on a new Department.jspx page, and then go in to add the Employee as an ADF Read Only page – I get more satisfactory results:

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc027

In order to have the table synchronize with the Form, I have added an id to the First, Last, Next and Previous navigation buttons and included these four id values in the partialTriggers attribute of the table component.

Alternative to Plcaeholder

There is an interesting alternative to the Placeholder Data Controls. It is illustrated in this article: Creating an ADF URL Service DataControl for binding a File or Servlet/JSP service and using it in an ADF Faces Web Application. It illustrates the creation of a URL based Data Control on a CSV file that is part of the application itself. That approach too allows for the creation of an ADF application running against an off line Data Control – no database required. I am not sure whether we can create master detail relationships that way though.

Rebind the ADF Faces components

It is all fine and well of course to create pages that are bound to Placeholder Data Controls, but at some point you may want to switch them over to ‘real’ Data Controls. Without a lot of hassle.

Now suppose next to the project containing the Placeholder Data Control with its Department and Employee data types we now have a Model project that contains ADF BC components – based on a database – that are exposed through a HrmService Data Control.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc028 

It is pretty straightforward to rebind the existing Table, (form) InputText and CommandButtons from the Placeholder Data Control to the HrmService. Simply by dragging the EmpView2 collection to the Employees table, the rebind dialog pops up:

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc029

I select ADF ReadOnly Table and the table is redefined based on the newly selected Data Collection.

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc030

Note that the rebind option is also available from the context menu on the table component in the Structure window. It feels like rebinding the table could be done in a more subtle way, without completely replacing all columns created previously for the Placeholder Data Control’s attributes. I will have to look into that to determine a better approach.

When I drag the Deptno attribute to the OutputText that is currently bound to the Deptno attribute in the Placeholder, I get this rebinding dialog. Without much fuss, I replace the data source for this component:

Some more details on ADF Placeholder Data Control (rebind component, master detail, load sample data from CSV file) placeholderdc031 

 

Something similar is done with the Navigation buttons.

And after all this rebinding Рtakes about 2 minutes РI have an application that is now real Рno longer just a fa̤ade Рhappily running against the backend database.

One Response

  1. Santosh August 5, 2011