ADF 12c: Adaptive applications through reusable bindings using 12c Dynamic components, runtime switching from ADF BC to a POJO data control v.v.

0
Share this on .. Tweet about this on TwitterShare on LinkedIn1Share on Facebook0Share on Google+0Email this to someoneShare on Tumblr0Buffer this page

The UK Oracle User group (UKOUG) held their Tech13, technology conference 2013, in Manchester 2 weeks ago. Duncan Mills held an interesting presentation on “Adaptive Applications”. He explained how to create fully reusable applications. Applications that can be used for different datasources and database tables. Just select a data model on runtime, and the application can show a page with a table. This can be done, eventhough using the ADFm Binding layer for all interactions by making it dynamic. With the dynamic binding layer is easy to reuse the same application with another data model or even with another database connection. You can imagine it’s power and think of the great many of use cases for this! In this blog I’ll describe how the new 12c dynamic components make life easy and I prove you can use just one iterator binding for both ADF business components and POJO data controls.

Step 1: Creating Business Components

First of all we have to create a Business Components layer. I used the HR schema and the option “Business Components from Tables” to quickly make a default HR data model containing an empoyee. Besides that I created a datacontrol from a “Car” pojo with a few class members: carId, brand and color. The result:

BC

Step 2: Create the view

Then create a Home.jspx page and drag a datacontrol on the page and select “Create ADF Table” (as you are used to). When the create table dialog appears you have to select the option “Generate columns dynamically at runtime”, which will create a dynamic table for you:

CreateTableDialog

What you get is the following source code:

Home_table

Here we notice a couple of things. First of all the “af:dynamicComponent” tag. The component that is rendered depends on the attribute’s data type. It supports: inputText, inputDate, inputListOfValues, selectOneChoice, selectManyChoice, selectOneListbox, selectManyListbox, selectOneRadio, selectBooleanRadio, selectBooleanCheckbox and selectManyCheckbox. This can be used with dynamic form as well.

Secondly notice the “af:iterator”. In 11g you were bound to the use the “af:forEach” tag. With the af:iterator we can enjoy the benefit of having unique IDs for our columns at runtime and the application will keep working when switching on MDS. One minor disadvantage is however that we cannot use table filtering with the af:iterator. If we would like that we have to use the af:forEach afterall. Perhaps Oracle will solve this in the next release.

 

Step 3: Make the binding layer dynamic

Creating a table, JDeveloper will create a Page definition with a tree binding for you. Note that the Attribute list is empty. You might expect that this means that none of the attributes will be shown in the table, however this means that all attributes/columns will be shown in the table. We make the ‘Binds’ and ‘DataControl’ attributes of the iterator tag dynamic. You can read the details of this in the blog `Towards Ultra-Reusability for ADF – Adaptive Bindings` by Duncan Mills. This is what we initially had:

BindingsBeforeChange

This is what we need:

BindingsAfterChange

You need to change all references in the af:table tag in your page to “EmployeesView1”, to point to “GenericView” and all works just fine. The attributes of the tree tag that are removed are redundant. They might be important in trees, but not in tables. This makes the binding fully dynamic, so that it can be used in a generic way.

You just made the ViewController part fully dynamic. At runtime you can change what data control is shown, by injecting the right data control name in the binding layer. If you want, you can run the application module against different connections as well. This can be achieved by making the bc4j.xcfg dynamic. You can read all about that in the blog ‘Adaptive Connections’ by Duncan Mills.

Step 4: Add the POJO datacontrol
To be able to use the pojo datacontrol in the same way through the dynamic binding layer, you need to set the variables ${pageFlowScope.HomePageDefBean.dcName} to “CarDC” and the ${pageFlowScope.HomePageDefBean.voName} var to “cars”. Don’t forget to add the datacontrol to de DataBindings.cpx in order for it to work:

databindings

Of course you can set the variables in the bindings at runtime with a “af:selectOneChoice” tag. The result is that you can select which datacontrol you want to show in your page and you can switch between ADF BC and POJO datacontrols all the same.

EmployeesView1 ADF BC data control:
employeesTable

cars POJO data control:
carsTable

 

This blog is also posted on: http://blog.jonathandamen.nl/

Resources

Download the sources: Dynamics_sources.

Oracle Documentation ‘About Determining Components at Runtime’ (http://docs.oracle.com/middleware/1212/adf/ADFUI/af_dynamic.htm#ADFUI13609)

Oracle Documentation ‘About Creating ADF Databound Tables’ (http://docs.oracle.com/middleware/1212/adf/ADFFD/web_tables_forms.htm#CHDJDCEB)

Article `Towards Ultra-Reusability for ADF – Adaptive Bindings` by Duncan Mills (https://blogs.oracle.com/groundside/entry/towards_ultra_reusability_for_adf)

Article `Adaptive Connections For ADFBC` by Duncan Mills (https://blogs.oracle.com/groundside/entry/adaptive_connections)

Article `ADF 11g: Query Component with ‘dynamic’ view criteria` by Luc Bors (http://lucbors.blogspot.co.uk/2011/10/in-my-current-project-use-lot-of-re.html)

Share this on .. Tweet about this on TwitterShare on LinkedIn1Share on Facebook0Share on Google+0Email this to someoneShare on Tumblr0Buffer this page

About Author

Oracle consultant at AMIS

Comments are closed.