Showing posts with label exception handling. Show all posts
Showing posts with label exception handling. Show all posts

Friday, February 14, 2014

ADF: Handling exceptions from BackingBeans inside bounded Taskflow explained


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


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:

  public void handleExceptionShowMessageInPopupDialog() {
    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