0% found this document useful (0 votes)
4 views28 pages

18-ADF Lifecycle

The document outlines the Oracle ADF lifecycle, detailing its integration with the JSF lifecycle and the various phases involved, including data model preparation, validation, and method execution. It explains how developers can interact with the lifecycle through custom phase listeners and controllers, allowing for tailored request handling and error management. Additionally, it provides examples of implementing custom listeners and controllers to enhance the ADF lifecycle functionality.

Uploaded by

chakradhar s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views28 pages

18-ADF Lifecycle

The document outlines the Oracle ADF lifecycle, detailing its integration with the JSF lifecycle and the various phases involved, including data model preparation, validation, and method execution. It explains how developers can interact with the lifecycle through custom phase listeners and controllers, allowing for tailored request handling and error management. Additionally, it provides examples of implementing custom listeners and controllers to enhance the ADF lifecycle functionality.

Uploaded by

chakradhar s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

18

Section 18
Oracle ADF – ADF Lifecycle
ADF Lifecycle

The ADF lifecycle:


y
• Hooks into the JSF lifecycle – JSF Phases are available in
ADF Lifecycle for developer to interact with the request
processing
• Handles:
• Data model preparation and update
• Data validation at the model layer
• Method execution on the business layer
• Uses the binding container to make data available during the
current page request
ADF Lifecycle Phases
JSF Phases ADF Phases Events

Restore View JSF Restore View before(JSF Restore View)


after(JSF Restore View)

Init Context before(Init Context)


after(Init Context)

Prepare Model before, after

Apply Request Values JSF Apply Request Values before, after

Process Validations JSF Process Validations before, after

Update Model Values JSF Update Model Values before, after

Validate Model Updates before, after

Invoke Application JSF Invoke Application before, after

Metadata Commit before, after

Render Response JSF Render Response before, after

Only after navigation before, after


Init Context

Only after navigation before, after


Prepare Model

Prepare Render before after


before,
The Big Picture
JSF Lifecycle Phases ADF Lifecycle Phases

Restore View JSF Restore View For Same View

Init Context New Init Context


Context
Prepare Model Prepare Model

Apply Request Values JSF Apply Request Values


Prepare Render

Process Validation JSF Process Validation

Update Model Values For Same View


JSF Update Model Values
Render Response
Validate Model Updates

Invoke Application JSF Invoke Applications


Prepare Render

Meta Data Commit

Changed yes
View?

no

Render Response
ADF Lifecycle in Action

Restore View:
• Th
The URL ffor the
th requested t d page is
i
passed to the bindingContext.
• Page definition file that matches the
URL is looked up.
JSF Restore
R t View:
Vi
• Provides before and after phase events
• You can create a listener and register it with the before or after event
• The Initialize Context p
phase of the ADF Model layery lifecycle
y listens for the
after(JSF Restore View) event and then executes.
Initialize Context:
• The page definition file is read to create the bindingContainer
• The LifecycleContext class used to persist information throughout the
ADF lifecycle phases is instantiated and initialized with values for the
associated request, binding container, and lifecycle.
ADF Lifecycle in Action

Prepare Model:
• Binding container page parameters
are prepared and evaluated.
• Taskflow parameters are passed
into the flow.
• Any executables that have their
refresh attribute set to prepareModel are refreshed
• If the page was using a template, and that template contains bindings
th t use the
that th ADF M Model
d l llayer, th
then th
the ttemplate's
l t ' page d
definition
fi iti file
fil iis
initiated
• If any task flow executable bindings exist (for example, if the page
contains a region),
g ), the task flow binding g creates an ADF Controller
ViewPortContext object for the task flow, and any nested binding
containers for pages in the flow are executed.
ADF Lifecycle in Action

Apply Request Values:


Each component in the tree extracts new
values from the request parameters:
JSF Apply Request Values:
Provides before and after phase events
Process Validations:
• If there are errors, the lifecycle jumps to the Render Response
phase
• Exceptions are also caught by the binding container and cached.
JSF Process Validations:
• Provides
P id b before
f and
d after
ft phase
h events
t
ADF Lifecycle in Action

Update Model Values:


• The component's validated local
values are moved to the model and
the local copies are discarded.
• For any updateable components (such as an inputText
i tT t
component), corresponding iterators are refreshed if the refresh
condition is set to the default (deferred) and the refresh condition (if
any)
y) evaluates to true
JSF Update Model Values:
Provides before and after phase events
Validate Model Updates:
p
• The updated model is now validated against any validation routines
set on the model.
• Exceptions are caught by the binding container and cached.
ADF Lifecycle in Action

Invoke Application:
Any action
A ti bibindings
di ffor command
d
components or events are invoked
JSF Invoke Application:
Provides before and after phase events
MetaData Commit
• Changes to runtime metadata are committed
• This phase stores any runtime changes made to the application using the
M t d t Service
Metadata S i (MDS)
Initialize Context
• If navigation occurs
• Initialize page definition file for the next page
Render Response
JSF Render Response:
Provides before and after p
phase events
Specifying When to Refresh Binding
Executables
• Refreshing iterator reconnects it with RowSetIterator object
• Refreshing invoke action binding invokes the action
• Can set refresh property to refresh:
• deferred (default): During both Prepare Model and Prepare
Render phases
• prepareModel: Just during Prepare Model phase
• renderModel: Just during Prepare Render phase
• never: Only when code calls getRowSetIterator()
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF

Interacting
g with the ADF
Lifecycle
Using the Lifecycle

• Declarative
• Control execution via executables "Refresh" attribute
• prepareModel
• renderModel
• Code
• PagePhaseListener – Decorates the lifecycle
• Custom page controller - subclass and extend the lifecycle for
a page
• Use with caution remember to call the super-class!
p
• Complete custom lifecycle
Interacting with the ADF Lifecycle

• Developers can create and configure custom life cycle listeners


to receive ADF lifecycle notifications at the beginning and the
end of each phase to execute custom logic
• Listeners can be used to customize the ADF Lifcycle
• Lifecycle listeners can be configured for the following scopes
• Global
• The page lifecycle listener is configured to execute for all lifecycle
execution throughout the application
• ADF bounded page
• The lifecycle listener is configured in the page definition file
• Programmatically
• A lifecycle listener is added programmatically from Java and
remains active until it is removed or the user session is dismissed
How-to create a custom Phase Listener

• ADF Controller is required !


• Objects that should receive lifecycle notifications must implement
the PagePhaseListener interface
• The method argument is an instance of PagePhaseEvent that
provides access to the following objects
• Lifecycle
• HttpServletRequest
• HttpServletResponse
• BindingContext
• BindingContainer objects

• PhaseId that returns the currently processed PhaseId as


an int value
Custom PhaseListener Example

import oracle
oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
adf controller v2 lifecycle PagePhaseEvent;
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;

public class CustomPageListener implements PagePhaseListener {


public CustomPageListener() {
super();
}
public void afterPhase(PagePhaseEvent pagePhaseEvent) {
String idStr = pagePhaseEvent.getPhaseId();
System out println("after
System.out.println( after "++ Lifecycle.getPhaseName(idStr));
Lifecycle getPhaseName(idStr));
}
public void beforePhase(PagePhaseEvent pagePhaseEvent){
String idStr = pagePhaseEvent.getPhaseId();
System.out.println("before "+ Lifecycle.getPhaseName(idStr));
}
}
Configuring a custom PhaseListener

• To create and configure


g g
global lifecycle
y listeners use
the adf-settings.xml configuration file
• The adf-settings.xml file does not exist by default and
needs to be created in the “.adf\META-INF
adf\META INF” folder of
the application
• The adf-settings.xml
g file allows developers
p to define
the order in which page phase listeners are invoked
• This guarante does not exist in standard JavaServer Faces
adf-settings Example

<?xml version=
version="11.0
0" encoding=
encoding="US
US-ASCII
ASCII" ?>
<adf-settings xmlns="http://xmlns.oracle.com/adf/settings">
<adfc-controller-config
xmlns="http://xmlns.oracle.com/adf/controller/config">
<lifecycle>
<phase-listener>
p
<listener-id>CustomPageListener1</listener-id>
<class>adf.interactive.view.CustomPageListener</class>
<before-id-set>
<listener-id> AnotherPageListener1</listener-id>
</before-id-set>
<after-id-set>
<listener-id>AnotherPageListener2</listener-id>
</after-id-set>
</phase-listener>
</lifecycle>
</adfc-controller-config>
</adf-settings>
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF

Global Lifecycle
y
Customization
Lifecycle Customization

• Modifies the behavior of the ADF request handling


g
• Allows developers to execute custom code in the
course of ADF request handling
• Change
Ch th
the way validation
lid ti or updates
d t are h handled
dl d
Custom Page Controller

import oracle
oracle.adf.controller.v2.context.LifecycleContext;
adf controller v2 context LifecycleContext;
import oracle.adf.controller.faces.lifecycle.PageController;

public class CustomPageController extends PageController {


public CustomPageController() {
super();
}
@Override
public void validateModelUpdates (LifecycleContext lifecycleContext){
//add your custom code here and optionally suppress the
//default behavior by commenting out the call to super
super.validateModelUpdates(lifecycleContext);
}
Setting a custom PageController in a
PhaseListener for all ADF pages to use
import javax.faces.event.PhaseId;
import oracle.adf.controller.v2.context.LifecycleContext;
i
import
t oracle.adf.controller.v2.lifecycle.PagePhaseEvent;
l df t ll 2 lif l P Ph E t
import oracle.adf.controller.v2.lifecycle.PagePhaseListener;

public class CustomPageListener implements PagePhaseListener{


public CustomPageListener()
p g {
super();
}
//lifecycle method to listen for the RESTORE_VIEW phase
//to set the custom controller
public
bli void
id afterPhase(PagePhaseEvent
ft Ph (P Ph E t pagePhaseEvent)
Ph E t) {
int RESTORE_VIEW_ID = PhaseId.RESTORE_VIEW.getOrdinal();
LifecycleContext lctx = pagePhaseEvent.getLifecycleContext();
if (pagePhaseEvent.getPhaseId() == RESTORE_VIEW_ID){
lctx.setPageController(new
g ( CustomPageController());
g ())
}
}
public void beforePhase(PagePhaseEvent pagePhaseEvent) {}
}
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF

Local Lifecycle
y
Customization
Custom Page Controller

import oracle
oracle.adf.controller.v2.context.LifecycleContext;
adf controller v2 context LifecycleContext;
import oracle.adf.controller.faces.lifecycle.PageController;

public class CustomPageController extends PageController {


public CustomPageController() {
super();
}
@Override
public void validateModelUpdates (LifecycleContext lifecycleContext){
//add your custom code here and optionally suppress the
//default behavior by commenting out the call to super
super.validateModelUpdates(lifecycleContext);
}
Customize Lifecycle of Single ADF
Page
• Use PageDef
g file to reference custom page
g controller
• Set ControllerClass property as shown below

<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
version="…"
id="homePageDef"
Package="adf.sample.view.pageDefs"
ControllerClass="adf.sample.CustomPageController">
ll l df l ll
Fusion Application Development with
Oracle JDeveoper 11g and Oracle ADF

Custom Error Handling


g
Custom Error Handling

• Previously required a whole custom lifecycle


• In 11g extend oracle.adf.model.binding.DCErrorHandlerImpl
• May override the following methods
• reportException
p p
• Override this method in a custom error handler to analyze the
exception for specific errors you want to handle yourself
• getDisplayMessage
• Override this method to change the message displayed to the client.
Returning a null value suppresses the display of the exception
• getDetailedDisplayMessage
• Override this method to provide HTML markup formatted detail
information for an error.
• Register ErrorHandlerClass in DataBindings.cpx

You might also like