Monday, January 25, 2010

Conditional Activation for ADF Regions and Application Availability

In ADF applications, in that case if database is down, user will get error message and site will be broken. If user will open site, when database was already down, user will see 'Loading' message and nothing else. If database will go down, during user activity - most likely NullPointerException will be raised and user will see broken site. Such behavior is not acceptable, enterprise services should be available even when database is not working. Ideally, database related content should be disabled and static content still should be loaded and available.

Today I have developed sample application, where regions are loaded conditionally, based on database availability. Download working sample -

We will follow such scenario - user is working with Departments and Jobs regions:

Suddenly, database goes down for some unknown reason:

User of course is not aware about database status and press Next button in Departments region:

At this point, ADF will generate Exception, however we can handle it with Error activity registered in ADF Task Flow:

Without closing browser, user can refresh site, and if database still will be down - only static content will be loaded, database related regions will be disabled (I will describe how you can achieve this after few steps):

This allows to present at least static content, which is much better comparing to Error page, I'm even not talking about visible exception.

New users, who will open site while database is still down, will get static content rendered as well:

Finally, when database will be back to life again:

It will be enough just to refresh browser (no need to close it and open again), regions will be activated automatically and dynamic content will be rendered:

Now I will explain how it is done. Thanks to ADF Regions functionality , we can activate them conditionally:

When we use conditional region activation, activation condition must be provided. In this case, I'm calling managed bean (request scope) where check is done for Application Module status:

Its enough to acquire Application Module instance reference, if database will be down, Application Module will be unavailable and exception will be thrown. We can catch this exception and deactivate regions:

Finally, Error activity should be defined in ADF Task Flow in order to handle exception, when database is going down during active session:


Karim H Abdellatif said...

Hello Andrejus,
nice practice

JIMENA said...

Hi, Andrejus, please, I need to make debugging of the expresion adf.userSession.userData.currentUserLanguage, but I need know how get user session without groovy, i.e. programatically from initdefaults() in a EO class.