Thursday, October 31, 2013

Handling exceptions in the ADF taskflow

-         Through exception handling we can designate an Activity as exception handler
-          For the flow from the exception handling activity uses the standard exception handling activity
-          You can use router as exception handling activity and reaching the exception from here it will can route to various control flow cases based on exception.
-          A task flow can have only one exception handling activity
-          If no exception handling mechanism provided the exception propagated to the top level tf till the webcontainer
-          ADF Model also provide exception handling mechanism. An exception thrown by any type of binding is caught by the ADF Model which calls the reportException() stores the exception in the binding container

-          Later page renders error displays

Create a task flow below 


For the testMeth1 activity attch the method as 

#{pageFlowScope.handleException.exception}

View1.jspx

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:button text="button 1" id="b1" action="toMeth"/>
  </af:panelGroupLayout>
</jsp:root>
testMeth1
#{pageFlowScope.handleException.exception}

The managed bean handleException

package view.test;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import oracle.jbo.JboException;

public class TestException {
    public TestException() {
        super();
    }

    public void exception() {
        throw new JboException("test here");
    }

    public void exceptionMessage() {
        System.out.println("Here");
        try {
            System.out.println("Inside Handeler");
            FacesMessage message = new FacesMessage("This is custom Message for Jbo Exception-Exception Handeler");
            message.setSeverity(FacesMessage.SEVERITY_WARN);
            FacesContext fc = FacesContext.getCurrentInstance();
            fc.addMessage(null, message);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void badCall() {
          
       }

    public String badActionHere() {
System.out.println("Here...");
        return null;
    }
}

Create a page to test by drag and drop the page as region and run.Click on the button and you see the custom exception message.



1 comment:

  1. How and when to use try and catch block in adf application...

    ReplyDelete