Scenario 1
Exception is thrown in actionListener Code for a commandButton inside a View of a bounded taskflow based on page fragments.
In our example Test1ViewBean is in Request-Scope and contains an ActionListener method that throws a NullPointerException for demo purposes.
This ActionListener is called from a command button
This ActionListener is called from a command button
The Default behaviour in this scenario is the following:
Of course this is not user friendly (+ may cause side effects) so we should use one of the provided ADF Exception handling mechanisms to fix that.
Solution to scenario 1:
Make a guess: (a) DCErrorHandler (b) BTF-Exception-Handler (c) UTF-Exception-Handler (d) Faces-ExceptionHandler (e) Servlet-Exception Handler
Tam da da dam: Solution is "(c) UTF-Exception-Handler" not "(b) BTF-Exception-Handler" as some of you might expect.
Let's see how it works. Create a Method-Activity in adfc-config.xml
and mark it as Exception-Handler.
The Method Activity points - by EL - to the following java method:
ControllerContext cc = ControllerContext.getInstance();
Exception ex = cc.getCurrentViewPort().getExceptionData();
String message = ex.getMessage();
FacesContext fc = FacesContext.getCurrentInstance();
FacesMessage facesMessage =
new FacesMessage(FacesMessage.SEVERITY_ERROR, "UTF: " + message, null);
fc.addMessage(null, facesMessage);
cc.getCurrentRootViewPort().clearException();
fc.renderResponse();
}
Having this Exception-Handler active on runtime the Exception is catched an displayed in a user friendly inline popup
Why the "(b) BTF-Exception-Handler" is not working in the given scenario?
Well, it is because the action event is handled in the standard JSF Lifecycle (invoke application phase) and not inside the ADF Controller of the bounded taskflow.
Download
In the sample application - based on ADF 11.1.1.7 - you can test the different cases and see how everything works in each scenario. enpit.sample.adf.testExceptionHandling-jdev11117.zip
Further Reading
- Oracle ADF: Catch me if you can http://www.oracle.com/technetwork/issue-archive/2013/13-mar/o23adf-1897193.html
- Exception Handler for Method Calls inside ADF Task Flows with Fragments - http://andrejusb.blogspot.de/2011/03/exception-handler-for-method-calls.html
- Task Flow Exception Handler. You must have it. http://adfpractice-fedor.blogspot.de/2011/12/task-flow-exception-handler-you-must.html
Good information Andreas, but exception thrown in Backing Bean method using Action->Method Activity->Backing Bean method call is caught by BTF exception handler, whereas both ActionListener and Action methods are called in standard JSF Invoke Application Lifecycle, so why does controller honor exception raised in Action and not in ActionListener when both are invoked during the same lifecycle phase ?
ReplyDeleteHi Tapash,
ReplyDeleteI guess because the action makes a navigation in the Controller. So BTF Exception HAndler is involved,
Regards,
Andreas