Today is a next post in integration series, check my previous posts for the same topic. I will describe how you can handle exceptions with ADF Task Flow exception handler activity. Usually, we define separate Web page and render it, when exception occurs. However, its not user friendly - its better to inform user about exception and remain in the system. I will explain one undocumented technique for exception handling - combination between ADF Task Flow exception handler activity and dynamic regions. Described approach is applicable not only to Oracle UI Shell, but to the screens with dynamic regions as well.
Download sample application - ADFIntegrationUIShell2.zip. This sample is based on my previous post about Oracle UI Shell - Oracle UI Shell Update Available (1.02). I simulated Null Pointer Exception in one of the libraries and implemented exception handling approach.
In Departments library, I intentionally changed Commit operation reference in backing bean from Commit to CommitCorrupt:
Page Definition file defines Commit operation, this means on runtime OperationBinding object will be NULL and Null Pointer Exception will be thrown when trying to execute it:
At first, let's follow most common approach and declare separate JSF page for exception handler activity in ADF Task Flow - error page:
We open Departments application in UI Shell:
If Save button will be pressed, it will generate Null Pointer Exception, because OperationBinding will not be found (as described above). Since we have declared Exception Handler activity on error page, this page will rendered and user will be navigated away from the system:
It is not good, because it will look as whole system is down - nothing is shown, no menus and no navigation buttons. Most of the users will close and open their Web browser again.
In order to make it more user friendly, let's remove error page and mark the same main page as error activity by itself. This means, whenever exception will happen in the system, we will not navigate to any specific error page - but will stay on the same main page (where UI Shell is implemented):
You may ask, how we inform user about exception? Its quite simple - we define and render separate dynamic region with information about exception. I have defined new ADF Task Flow with one fragment - error.jsf:
This means in case of exception, we render only error fragment, and main page will remain the same - all menus and navigation buttons will remain present. How we can do this? Let me describe.
Oracle UI Shell contains facet for welcome region, instead having static region there, we can have dynamic. Let's add dynamic region ID calculation method into UI Shell launcher bean:
Now we need to change static welcome region ID:
To dynamic one from UI Shell launcher bean:
We have welcome region and can generate it dynamically. Now we need to define a reference to dynamic error region. In order to render error region only when its needed, we need to add some logic into dynamic region ID calculation method. First, we access ControllerContext object in order to check if there is any registered exception. And if there is exception, we clear this exception, close all currently open tabs and render error region. Because we declared ADF Task Flow exception handler on the same main page, after exception happens, framework again renders the same page and it triggers dynamic region ID calculation method - where we can render error region now, instead of default welcome region:
We need to clear exception, otherwise it will remain in ControllerContext object during next requests.
Now, we test the same Departments application and press Save button to generate Null Pointer Exception:
System is not navigating anymore to error page, but instead renders error region:
This is great, because user can use menu items and navigation buttons, to continue his work with the system: