Sunteți pe pagina 1din 25

Passing Values

Between
UI Elements

Copyright 2008, Oracle. All rights reserved.


Objectives

After completing this lesson, you should be able to do the


following:
Define the data model to reduce the need to pass values
Use a managed bean to hold values
Use page parameters
Use task flow parameters
Pass values from containing pages to regions

18 - 2 Copyright 2008, Oracle. All rights reserved.


Holding Values in the Data Model
(Business Components)

Define transient attributes to hold values.


Row concurrency can coordinate multiple pages without
parameter passing.
Defining view links in the data model:
Coordinates master and detail pages
Re-executes queries as needed
Reduces the need to pass parameters between UI pages
and regions

18 - 3 Copyright 2008, Oracle. All rights reserved.


Holding Values in Managed Beans

Managed beans are optional and can be used to:


Hold values
Store state
How?
Managed properties
Scoped managed bean variables

18 - 4 Copyright 2008, Oracle. All rights reserved.


Using Managed Properties

Managed bean variables that are exposed through getter


and setter methods
Configured in the .xml file of the task flow
Possible values:
null
Literal string
Lists and Maps
Value binding expression (EL)

18 - 5 Copyright 2008, Oracle. All rights reserved.


Managed Properties: Examples

Literal string:
<managed-bean>
<managed-property>
<property-name>label</property-name>
<value>Hello World</value>
</managed-property>
EL (accessing a managed bean):
<managed-bean>
<managed-property>
<property-name>label</property-name>
<value>#{Userbean['firstname']}</value>
</managed-property>

18 - 6 Copyright 2008, Oracle. All rights reserved.


Using Scoped Managed Bean Variables

JSF scopes: Additional ADF Faces scopes:


application view (ADF Faces)
session pageFlow (ADF Faces)
request backingBean (only for page fragments or
none declarative components)
Why use scopes?
Save state of model
Enables passing values to other pages or phases
pageFlow scope:
Retains values for current process (page flow) only
Independent of other processes, unless using LaunchEvent
Can be accessed via EL or Java
Can be explicitly cleared

18 - 7 Copyright 2008, Oracle. All rights reserved.


Accessing pageFlowScope from a Page

You can access pageFlowScope variables by using:


EL:
<af:commandButton
text="#{pageFlowScope.buttonBean.label}"
action="#{pageFlowScope.buttonBean.action}"/>
Java:
import java.util.Map;
import
org.apache.myfaces.trinidad.context.RequestContext;
. . .
Map pageFlowScope =
RequestContext.getCurrentInstance().getPageFlowScope()
;
Object myObject = pageFlowScope.get("myObjectName");

18 - 9 Copyright 2008, Oracle. All rights reserved.


Using pageFlowScope Without Writing Java Code

<af:table The Master page stores an employee


value="#{myManagedBean.allEmployees}" row in pageFlowScope variable
var="emp" rowSelection="single"> 1empDetail.
<af:column headerText="Name">
<af:outputText value="#{emp.name}"/>
</af:column>
<af:column
headerText="Department Number"> The Detail page retrieves employee
<af:outputText data from pageFlowScope variable
value="#{emp.deptno}"/>
empDetail.
</af:column>
<af:column headertext="Select"> <h:panelGrid columns="2">
<af:commandButton <af:outputText value="Firstname:"/> 4
text="Show more details" <af:inputText
action="showEmpDetail">
2 value="#{pageFlowScope.empDetail.name}"/>
<af:setActionListener <af:outputText value="Email:"/>
<af:inputText
from="#{emp}" 3 value="#{pageFlowScope.empDetail.email}"/>
to=
"#{pageFlowScope.empDetail}"/> <af:outputText value="Hiredate:"/>
</af:commandButton> <af:inputText
</af:column> value="#{pageFlowScope.empDetail.hiredate}"/>
</af:table> <af:outputText value="Salary:"/>
<af:inputText
value="#{pageFlowScope.empDetail.salary}"/>
</h:panelGrid>

18 - 10 Copyright 2008, Oracle. All rights reserved.


Using Parameters

You can use:


Page parameters
Task flow parameters
Region parameters
View activity parameters
Task flow call activity parameters

18 - 11 Copyright 2008, Oracle. All rights reserved.


Using Page Parameters

Define page parameters in the Structure window for a page


definition file:

#{bindings.nameToPass}

18 - 12 Copyright 2008, Oracle. All rights reserved.


The Job of the Page Parameter

Receives a value and stores it in a parameter in the binding


container:
Parameter Parameter name Parameter value Parameter function
type
Containing output nameToPass #{'Pam'} Receive a value and store
page it in binding container.
parameter

18 - 13 Copyright 2008, Oracle. All rights reserved.


Using Task Flow Parameters

1. The pname parameter is passed into the task flow, and its
value is assigned to the pageFlowScope variable pname.
2. Inside the task flow, activities and pages can get the value
of the parameter using the EL expression:
#{pageFlowScope.pname}

18 - 14 Copyright 2008, Oracle. All rights reserved.


The Job of the Task Flow Parameter

Stores input value into page flowscoped variable:


Parameter Parameter name Parameter value Parameter function
type
Containing output nameToPass #{'Pam'} Receive a value and store
page it in binding container.
parameter

?
Bounded input pname #{pageFlowScope. Store parameter value in
task flow pname} page flowscoped
parameter variable.

Page #{pageFlowScope.pname}
fragment in
task flow

18 - 16 Copyright 2008, Oracle. All rights reserved.


Using Region Parameters

1. Define a page parameter and a parameter on the task flow


as in previous slides.
2. In the page definition file for the containing page, define
the same parameter on the region and set its value to the
page parameter:

3. Within the task flow, use pageFlowScope to access the


parameter value: <af:outputLabel value="Hello, "/>
<af:spacer width="10" height="10"/>
<af:outputText value="#{pageFlowScope.pname}"/>

18 - 17 Copyright 2008, Oracle. All rights reserved.


The Job of the Region Parameter

Passes the value from the page to its task flow:


Parameter Parameter name Parameter value Parameter function
type
Containing output nameToPass #{'Pam'} Receive a value and store
page it in binding container.
parameter

Region output pname #{bindings. Store binding value as


parameter nameToPass} parameter.

Bounded input pname #{pageFlowScope. Store parameter value in


task flow pname} page flowscoped
parameter variable.

Page #{pageFlowScope.pname}
fragment in
task flow

18 - 18 Copyright 2008, Oracle. All rights reserved.


Developing a Page Independently of a Task Flow

Page not aware of the task flows page flowscoped variable:


Parameter Parameter name Parameter value Parameter function
type
Containing output nameToPass #{'Pam'} Receive a value and store
page it in binding container.
parameter

Region output pname #{bindings. Store binding value as


parameter nameToPass} parameter.

Bounded input pname #{pageFlowScope. Store parameter value in


task flow pname} page flowscoped
parameter variable.

?
Page #{pageFlowScope.ename}
fragment in
task flow

18 - 19 Copyright 2008, Oracle. All rights reserved.


Passing Parameters from a Task Flow to One of
Its Pages

Use view activity parameter:

18 - 20 Copyright 2008, Oracle. All rights reserved.


The Job of the View Activity Parameter

Populates the page flowscoped variable expected by the page:


Parameter Parameter name Parameter value Parameter function
type
Containing output nameToPass #{'Pam'} Receive a value and store
page it in binding container.
parameter

Region output pname #{bindings. Store binding value as


parameter nameToPass} parameter.

Bounded input pname #{pageFlowScope. Store parameter value in


task flow pname} page flowscoped
parameter variable.

View activity internal #{pageFlowScope. #{pageFlowScope. Store page flowscoped


parameter ename} pname} variable into page flow
scoped variable expected
by the reusable page.

Page #{pageFlowScope.ename}
fragment in
task flow

18 - 21 Copyright 2008, Oracle. All rights reserved.


Summary: Passing a Value from a Page
to a Reusable Page Fragment in a Region

Containing Page Page parameter

Region Region
parameter
Task Flow Task flow
parameter
View Activity
View activity
parameter

Page Fragment

18 - 22 Copyright 2008, Oracle. All rights reserved.


Passing Values to a Task Flow from a Task Flow
Call Activity

1. Define an input parameter on the task flow call activity:

2. Define an input parameter on the called task flow.


18 - 23 Copyright 2008, Oracle. All rights reserved.
Returning Values to a Calling Task Flow

To return a value, you must specify:


Return value definitions on the called task flow
Return values on the task flow call activity in the calling task
flow
Names must match.

18 - 25 Copyright 2008, Oracle. All rights reserved.


Deciding Which Type of Parameter to Use

Parameters are designed to:


Improve reusability
Encapsulate functionality
You can use more than one type of parameter to achieve
these goals.

18 - 27 Copyright 2008, Oracle. All rights reserved.


Summary

In this lesson, you should have learned how to:


Define the data model to reduce the need to pass values
Use a managed bean to hold values
Use page parameters
Use task flow parameters
Pass values from containing pages to regions

18 - 28 Copyright 2008, Oracle. All rights reserved.


Practice 18 Overview:
Passing Values Between Pages

This practice covers the following topics:


Conditionally displaying tables based on parameters
Changing a panel header title based on parameters

18 - 29 Copyright 2008, Oracle. All rights reserved.

S-ar putea să vă placă și