Exception handling is one of the important aspect of any application. In below example i will explain how to handle exception/errors in adf taskflows with the help of taskflow-template.
Create a generic taskflow-template which contains the exception handling logic may be a method(java code) or a page. Use the same taskflow-template when you are creating a taskflow. Whenever exception is thrown, taskflow-template will handle it.
Below image show a method marked as exception handler in taskflow-template. It is nothing but one java code with some logic.
Using this template create a taskflow as shown below.
In this taskflow add 2 activities, one will be a page containing a button which will call processData method. This method throws an exception.
Thrown exception will be handled in one method which is there in taskflow template. When exception is thrown you can see the below message.
Java code handling exception :
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import oracle.adf.controller.ControllerContext;
import oracle.adf.controller.ViewPortContext;
import oracle.jbo.JboException;
public class ErrorHandeler {
public ErrorHandeler() {
super();
}
public void controllerExceptionHandler() {
ControllerContext context = ControllerContext.getInstance();
ViewPortContext currentRootViewPort = context.getCurrentRootViewPort();
Exception exceptionData = currentRootViewPort.getExceptionData();
if (currentRootViewPort.isExceptionPresent()) {
exceptionData.printStackTrace();
currentRootViewPort.clearException();
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, exceptionData.getMessage(), null));
}
}
public void processData() {
throw new JboException("Custom Exception Handling in Adf");
}
}
In taskflow itself you can mark any activity as a exception handler and use it.
Comments
Post a Comment