Friday, March 16, 2012

Adding UI Facets into ADF Page Template Based on Facelets Type

If you will try to add UI Facet into ADF Page Template based on Facelets type (JDeveloper 11g R2) - you may get into trouble of accessing UI Facet from consuming fragment/page.

Here is what I mean - assume there is a template created based on Facelets type:


This template contains UI Facet - we drag and drop it from Component Palette:


Facelets type fragment is created based on Facelets template:


We try to access UI Facet inside fragment - but its not accessible:


Declared UI Facet is not accessible even from Structure window:


This is because of error in ADF Template - related to Facet definition:


JDeveloper creates (when you drag and drop Facet component) invalid Facet definition for ADF Template based on Facelets (it works well for JSP XML template). Facet definition error - remove wrong facet definition manually:


We can workaround this, by going into Facet Definitions section and manually defining facet for the template with the same name - content:


As you can see, facet definition is correct now and is based on afc tag:


Facet is available from consuming fragment:


Download sample application - FaceletsTemplateUI.zip.

Thursday, March 15, 2012

Use Case for ADF BC With No Database Connection

There is very good sample application from Steve Muench - #147 ADFBC Application With No Database Connection (not yet documented). I was using it to implement recent request from the project, its why I would like to document it. We had a discussion with SOA developers and they were wondering if its possible to run ADF BC application, without DB access. This is quite common use case in SOA projects, there is no direct access to DB and we need to consume data through Web Service layer, as for example. Yes its possible and I see quite strong advantage of ADF BC, even when working with non DB data sources - its easy to centralize data access through programmatic VO's, its fast to expose programmatic VO through Data Control and finally is easy to capture user data input, use out of the box functions to process user data (getting current row from VO, iterating over row set, creating new rows, deleting rows, etc.). This can be as alternative for Web Service Data Control.

Sample application - ADFBCNoDatabaseWSApp.zip use case is described in this diagram:


ADF BC application is disabled from creating database connection, instead it contains programmatic VO to retrieve data from alternate data source.

I would recommend to check Steve Muench sample #147 (see link above), for this use case I took original code and migrated it to JDev 11g R2:


If you want to disable database access for ADF BC application, you will need to update bc4j.xcfg with proper entries. I would recommend to update this file from outside, not from JDeveloper - otherwise you may experience errors - seems like JDeveloper IDE is constantly scanning changes from bc4j.xcfg. Make sure to update bc4j.xcfg as from sample application, for example RequiresConnection=false and other settings:


Default Connection Strategy is extended to disable database connection:


Application Pool is disabled to perform passivation:


Handle Commit and Handle Rollback methods are disabled:


We are done with extending framework. Now I can describe simple use case - programmatic VO to retrieve user roles from WebLogic security provider (based on my previous post). Programmatic VO is reading data from WebLogic security provider:


View Object doesn't have any SQL statement, obviously it retrieves data from non database source:


When building ViewController, we can use regular Data Control - same as we would have from standard ADF BC:


Data is rendered successfully on ADF UI:


In this case, application runs independently of database and we still can use all powerful ADF BC data processing features.

Saturday, March 10, 2012

Opening ADF PopUp on Page Load

You may have requirement to capture user parameters, before navigating to actual page. This can be implemented by opening ADF popup during page load. User provides required information and confirms it by closing popup - actual page is rendered based on dialog action.

Sample application - IntroPopUpApp.zip, is implemented based on following process:


With ADF Faces its pretty easy to open user friendly popup on page load. All what developer needs to do is to define af:showPopupBehavior operation for af:document tag:


af:showPopupBehavior trigger type should be set to load. This will ensure, it will be executed during document load and will call popup during page rendering phase:


PopUp is rendered on page load:


Such functionality can be very useful, when we need to set bind variable value for VO, based on user input. Instead of building separate data entry page, we can handle user data entry from on-load popup.

Thursday, March 8, 2012

Extending Application Module for ADF BC Proxy User DB Connection

In this post I will describe how to retrieve database connection for ADF BC proxy user connection. I will provide best practice as well, how to implement Common AM and extend your local AM with common functionality. In the next post will test how ADF BC proxy user approach works when database connection pooling is enabled. We are using proxy user connection approach, when there is requirement to login into database with Web user. Such connection can be established through JDBC Data Source proxy user:


Its often happens to see database connection for proxy user is retrieved from dummy prepared statement, as described on this blog- we are bypassing ADF BC offered functionality in this way:


However, there is another way - we can use standard ADF BC methods and retrieve database connection from ADF BC transaction factory. How to implement it in generic way? Download sample application - AMExtendApp.zip, I will describe how this sample is implemented.

I have two Model projects - one contains common classes together with common AM, another consumes common Model and contains actual Model implementation:


Common Model extends ADF BC database transaction factory:


Database transaction implementation class provides public method to retrieve database connection:


Common Model AM Implementation class contains overriden prepareSession method, where we are getting DB connection from transaction factory and opening proxy connection for current Web user. This is main method, where proxy connection is established:


Common Model AM Implementation class is declared to be Base Class for CommonModel AM:


This is visible from AM Component Class:


Make sure to set transaction factory for Common Model AM - TransactionFactory property in AM configuration:


We switch now to our local AM, from Model project. Select this AM to extend from CommonModule - it will inherit custom base classes with generic prepareSession method:


Thats all, no need to change anything for local AM - it will invoke prepareSession from common AM automatically. Just double check you have set JDBC Data Source for AM connection:


JDBC Data Source connects as APPUSER:


Web user connects as HR (same as DB schema name):


HR schema data is retrieved successfully through proxy APPUSER:


Select statement is executed for Employees table from HR schema:


When passivation/activation happens, we can see that PS_TXN table is created in APPUSER schema (as expected in proxy user schema):


One more hint, if you get DB transaction cast error from prepareSession:


Make sure to set custom transaction factory class for local AM as well. When extending AM from common AM, only custom classes and VO instances are retrieved, but not AM properties:


Saturday, March 3, 2012

Proxy ViewObject and Dynamic Editable UI in ADF

ADF Bindings and Data Control maps together ADF BC and ADF UI. Mapping by default is static, means ADF UI renders data collection from specific VO mapped during design time. Sometime we have requirement to change data collection rendered on ADF UI during runtime. Dynamic UI can be implemented with dynamic VO's in combination with ADF Faces Dynamic Tags (Shay Shmeltzer's blog - ADF Faces Dynamic Tags - For a Form that Changes Dynamically). Dynamic VO's are created from SQL statements during runtime - such VO's will be readonly and hard to maintain. Moreover, its very hard to customize ADF Faces Dynamic Tags layout for custom UI requirements. We can set iterator binding in Page Definition dynamically, but this works only for Master-Detail VO instances - Dynamic Iterator Binding to Reuse View Link Relationship for Master-Detail. I will present in this blog post different technique how to implement dynamic editable ADF UI, assuming number of rendered attributes is not changing - but changing data collection.

Our task - to split ADF BC and ADF UI, allow to switch during runtime from one VO to another:


Sample application - DynamicVoApp.zip, implements such use case where we switch between different VO's retrieving data from different tables (we assume VO attribute names are the same, even underlying DB table column names are different). This is common scenario for business transactional systems, such systems tend to have large number of small tables with same columns and you need to minimize number of ADF UI to render such tables based on user role, etc. Of course we could build 100 different ADF UI screens for each of 100 tables - but we can be little smarter and build only 1 ADF UI screen to render all 100 different tables. Let's see how.

First we need to define dummy proxy VO, with select * from dual - we will use this proxy VO to access real VO through Data Control from ADF UI. DataView dummy VO will act as proxy VO:


Dummy VO - DataView defines all attributes to be accessible from ADF UI and to be defined in Page Definition file (Id and Name):


Real VO - DepartmentsView, must have exactly same names for attributes as we have defined in DataView. This is important, otherwise ADF Binding will fail to retrieve attributes from Page Definition on runtime - DepartmensView (Id attribute maps with Id, Name attribute maps with Name):


Same for JobsView, only difference - Name attribute maps with Title:


AM Data Model includes only DataView, only proxy dummy VO is accessible from ADF UI in our case:


There is custom method exposed in AM, this method will be invoked as Task Flow initializer and prepare real VO to be used through proxy DataView VO:


Here is main logic for sample application - changeVOInstance(voName) method:


This method logic:

1. Get proxy DataView VO
2. Remove proxy DataView VO definition
3. Find real VO definition by path name using ViewDefImpl.findDefObject(voName) function
4. Substitute proxy DataView VO with real VO definition, by creating real VO instance under proxy VO name using createViewObject("DataView",  voDefImpl)

Method is invoked as initializer method from Task Flow:


Task Flow accepts VO path name parameter, it is passed as parameter to custom method:


Task Flow parameter is passed through PageFlow scope and Task Flow is set to be refreshed when parameter value changes (ifNeeded):


ADF UI is based on typical ADF UI component, no dynamic components - means highly customizable:


ADF UI bindings are pointing to Page Definition, where mapping with proxy DataView is defined:


On runtime, by default we render editable JobsView (Id and Title labels) - Jobs data:


Click Open Departments button - proxy DataView will be switched and DepartmentsView will be rendered instead (Id and Name labels) - Departments data:


This approach allows to edit and update rendered data:

As you can see, just with one ADF screen we have implemented two use cases - Jobs and Departments editable UI's.