Friday, April 5, 2013

How to Customize the ADF Page Lifecycle to Work Programmatically with Bindings


Globally Customizing the ADF Page Lifecycle

To globally customize the ADF Page Lifecycle, do the following:
  • Create a class that extends oracle.adf.controller.faces.lifecycle.FacesPageLifecycle
  • Create a class that extends ADFPhaseListener and overrides the createPageLifecycle() method to return an instance of your custom page lifecycle class.
  • Change your faces-config.xml file to use your subclass of ADFPhaseListener instead of the default ADFPhaseListener. As shown in Figure 10-12, you can do this on the Overview tab of the JDeveloper faces-config.xml editor, in the Life Cycle category.

Note:
Make sure to replace the existing ADFPhaseListener with your custom subclass of ADFPhaseListener, or everything in the JSF / ADF lifecycle coordination will happen twice!

Figure 10-12 Setting Up a Custom ADFPhaseListener To Install a Custom Page Lifecycle Globally
Image of faces-config.xml editor
The SRDemo application includes a SRDemoPageLifecycle class that globally overrides the reportErrors() method of the page lifecycle to change the default way that exceptions caught and cached by the ADF Model layer are reported to JSF. The changed implementation reduces the exceptions reported to the user to include only the exceptions that they can directly act upon, suppressing additional "wrapping" exceptions that will not make much sense to the end user.

Customizing the Page Lifecycle for a Single Page

You can customize the lifecycle of a single page setting the ControllerClass attribute of the pageDefinition to identify a class that either:
  • Extends oracle.adf.controller.v2.PageController class
  • Implements oracle.adf.controller.v2.PagePhaseListener interface
The value of the page definition's ControllerClass attribute can either be:
  • A fully qualified class name
  • An EL expression that resolves to a class that meets the requirements above
Using an EL expression for the value of the ControllerClass, it is possible to specify the name of a custom page controller class (or page phase listener implementation) that you've configured as a managed bean in the faces-config.xml file. This includes a backing bean for a JSF page, provided that it either extended PageController or implements PagePhaseListener.
Figure 10-13 illustrates how to select the root node of the page definition in the Structure window to set.
Figure 10-13 Setting the ControllerClass of a Page Definition
Image of setting a controller class in Property Inspector

Note:
When using an EL expression for the value of the ControllerClass attribute, the Structure window may show a warning, saying the "#{YourExpression}" is not a valid class. You can safely ignore this warning.
Related Posts Plugin for WordPress, Blogger...