Pages

Thursday, November 20, 2014

Show exceptions caught in Managed Beans

There are couple of scenarios when some exception is caught while executing some logic in managed bean. The post is about how to show those exceptions to user and when it is required to do it explicitly.

For most of the scenarios, ADFm Error Handlers shows the message. But in case when some exception occurs in managedBean, it can be caught and reported to ADFm Error Handler using below code.

BindingContext bctx = BindingContext.getCurrent();
   ((DCBindingContainer)bctx.getCurrentBindingsEntry()).reportException(ex);

Note : Using the ADF model error handling for displaying exceptions thrown in managed beans require the current ADF Faces page to have an associated PageDef file (which is the case if the page or view contains ADF bound components).

Sample App is uploaded here. Following scenarios are covered  :

Scenario Description Button Text in Sample App Requires Explicit Handling to show messaage to User
1 Drag and Drop AM Method on Page as command Button throwJboExceptionFromAM No
2 Call AM method in Bean method through bindings Call throwJboExceptionFromAM in Bean through Bindings No. By default, all exception are handled by ADFm Error Handler when calling AMMethod through bindings. When you check for exception in operationBinding and report it expliclity .. It is basically duplicating the message
3 throw an exception in ActionListener ThrowingExceptionInActionListener Yes. See the button in section Handled and it's actionListener. How the exception is reported .


Enjoy !!!