Object Scope Lifecycles Oracle Fusion Middleware Online Documentation Library

Using the JSF Lifecycle with ADF Faces 4-17 navigates from one page to another, even if you use a redirect directive. But unlike session scope, these values are visible only in the current page flow or process. If the user opens a new window and starts navigating, that series of windows will have its own process. Values stored in each window remain independent. Like objects stored in any standard JSF scope, objects stored in the pageFlow scope can be accessed through EL expressions. The only difference with the pageFlow scope is that the object names must use the pageFlowScope prefix. For example, to have a buttons label provided by a managed bean stored in the pageFlow scope, and to have a method on the bean called when the button is selected, you might use the following code on your page: af:commandButton text={pageFlowScope.buttonBean.label} action={pageFlowScope.buttonBean.action} The pageFlowScope is a java.util.Map object that may be accessed from Java code. The setPropertyListener tag allows you to set property values onto a scope, and also allows you to define the event the tag should listen for. For example, when you use the setPropertyListener tag with the type attribute set to action, it provides a declarative way to cause an action source for example, commandButton to set a value before navigation. You can use the pageFlowScope scope with the setPropertyListener tag to pass values from one page to another, without writing any Java code in a backing bean. For example, you might have one page that uses the setPropertyListener tag and a command component to set a value in the pageFlowScope scope, and another page whose text components use the pageFlowScope scope to retrieve their values. You can also use the pageFlowScope scope to set values between secondary windows such as dialogs. When you launch secondary windows from, for example, a commandButton component, you can use a launchEvent event and the pageFlowScope scope to pass values into and out of the secondary windows without overriding values in the parent process.

4.7.1 How to Use the pageFlowScope Scope Within Java Code

You can access pageFlow scope from within any Java code in your application. Remember to clear the scope once you are finished. To use pageFlowScope in Java code: 1. To get a reference to the pageFlowScope scope, use the org.apache.myfaces.trinidad.context.RequestContext. getPageFlowScope method. For example, to retrieve an object from the pageFlowScope scope, you might use the following Java code: import java.util.Map; import org.apache.myfaces.trinidad.context.RequestContext; . . . Map pageFlowScope = RequestContext.getCurrentInstance.getPageFlowScope; Object myObject = pageFlowScope.getmyObjectName;

2. To clear the pageFlowScope scope, access it and then manually clear it.

For example, you might use the following Java code to clear the scope: Note: If your application uses ADF Controller, then you do not have to manually clear the scope. 4-18 Web User Interface Developers Guide for Oracle Application Development Framework RequestContext afContext = RequestContext.getCurrentInstance; afContext.getPageFlowScope.clear;

4.7.2 How to Use the pageFlowScope Scope Without Writing Java Code

To use the pageFlowScope scope without writing Java code, use a setPropertyListener tag in conjunction with a command component to set a value in the scope. The setPropertyListener tag uses the type attribute that defines the event type it should listen for. It ignores all events that do not match its type. Once set, you then can access that value from another page within the page flow. To set a value in the pageFlowScope scope: 1. On the page from where you want to set the value, create a command component using the Component Palette.

2. In the Component Palette, from the Operations panel, drag a Set Property

Listener and drop it as a child to the command component. Or right-click the component and choose Insert inside Button ADF Faces setPropertyListener .

3. In the Insert Set Property Listener dialog, set the From field to the value that will

be set on another component. For example, say you have a managed bean named MyBean that stores the name value for an employee, and you want to pass that value to the next page. You would enter {myBean.empName} in the From field.

4. Set the To field to be a value on the pageFlowScope scope.

For example, you might enter {pageFlowScope.empName} in the To field. 5. From the Type dropdown menu, choose Action. This allows the listener to listen for the action event associated with the command component. To access a value from the pageFlowScope scope: 1. On the page from which you want to access the value, drop the component that you want to display the value.

2. Set the value of the component to be the same value as the To value set on the

setPropertyListener tag. For example, to have an outputText component access the employee name, you would set the value of that component to be {pageFlowScope.empName}.

4.7.3 What Happens at Runtime: Passing Values

When a user clicks a command button that contains a setPropertyListener tag, the listener executes and the To value is resolved and retrieved, and then stored as a property on the pageFlowScope scope. On any subsequent pages that access that property through an EL expression, the expression is resolved to the value set by the original page. Tip: Instead of using the setActionListener tag which may have been used in previous versions of ADF Faces, use the setPropertyListener tag and set the event type to action.