In this blog entry I will show you how powerful ADF Task Flow are and how it can save you a lot of time. You only have to build it ones and use it everywhere. In this example I use an Exception page in a bounded Task Flow as a reusable component. In every Task Flow you can define a Exception Handler which takes care of the not handled exceptions. So probably you build this exception page in every project. I only have to drag the exception Task Flow from the component palette to the Task Flow, define some input parameters and make this Exception TF the Exception handler of the application Task Tlow.
This is how my exception page looks like. The Title and the Branding are flexible so you can change it in every Task Flow ( Task Flow input parameters)
First we create a project where we add an exception JSF template. This template has two facets Top and Body and 3 attributes Title , Branding ( Image component ) and Stacktrace.
Now we can add a new deployment profile to this project , select the ADF Library JAR File and deploy this template.
Create a new project with a bounded Task Flow ( de-select the page fragments option ) . In this Task Flow we add a new view.
Add the Title and Branding input parameters to this Task Flow definition.
The next step is to add the template library so we can use the exception jsf template. Create a new page ( select the view in the TF and use the right button to create the page). In the create page dialog we can select exception template. Here is the source of the jsf page where the templates attributes are connected to the input parameter of the TF
<?xml version='1.0' encoding='windows-1252'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=windows-1252"/>
<f:view>
<af:document>
<af:form>
<af:pageTemplate viewId="/templates/ExceptionTemplate.jspx">
<f:facet name="header"/>
<f:facet name="body"/>
<f:attribute name="branding" value="#{pageFlowScope.inputBranding}"/>
<f:attribute name="title" value="#{pageFlowScope.inputTitle}"/>
<f:attribute name="stacktrace" value="#{Exception.stacktrace}"/>
</af:pageTemplate>
</af:form>
</af:document>
</f:view>
</jsp:root>
To get the stacktrace, I need to use a bean and pass this value to the stacktrace attribute of the jsf template
package nl.ordina.view.exception.bean;
import java.io.PrintWriter;
import java.io.StringWriter;
import oracle.adf.controller.ControllerContext;
public class ExceptionBean {
private ControllerContext cc;
public ExceptionBean() {
cc = ControllerContext.getInstance();
}
public String getStacktrace() {
if ( cc.getCurrentViewPort().getExceptionData()!=null ) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
cc.getCurrentViewPort().getExceptionData().printStackTrace(pw);
return sw.toString();
}
return null;
}
}
Add this bean as backing bean in the bounded TF.
Create a new deployment profile , select the ADF Library JAR File and deploy this Task Flow.
finally we can use this Exception page in our applications by adding the ADF library to the project and drag the exception TF to our application TF's
Make this view the exception handler
Put some values to the Title and Branding parameters and we are finished.
Here is the project code.