You are on page 1of 386

Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
a f er
Oracle Fusion s
an Middleware
- t r
on ฺApplications with
11g: nBuild
ADF
s a I ide
) a
h t Gu
i l ฺ comtudeActivity
n Guide
g ma is S
o@ th
ฺvin
C (ac
d A
n o
Vi

D53979GC20
Edition 2.0
July 2010
D68162
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Disclaimer

This document contains proprietary information and is protected by copyright and other intellectual property laws. You may copy and
print this document solely for your own use in an Oracle training course. The document may not be modified or altered in any way.
Except where your use constitutes "fair use" under copyright law, you may not use, share, download, upload, copy, print, display,
perform, reproduce, publish, license, post, transmit, or distribute this document in whole or in part without the express authorization
of Oracle.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

The information contained in this document is subject to change without notice. If you find any problems in the document, please
report them in writing to: Oracle University, 500 Oracle Parkway, Redwood Shores, California 94065 USA. This document is not
warranted to be error-free.

Restricted Rights Notice

If this documentation is delivered to the United States Government or anyone using the documentation on behalf of the United
States Government, the following notice is applicable:

U.S. GOVERNMENT RIGHTS


The U.S. Government’s rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted
u se
by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract.
e to
Trademark Notice
n s
ice
owners. b l el
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective

fe ra
a n s
Authors
n - tr
Kate Heap, Patrice Daux
a no eฺ
h a s uid
m) ent G
Technical Contributors and Reviewers
Joe Greenwald, Glenn Maslen ฺco
a il Stud
g m is
o@ using:
This book was published th Oracle Tutor
v i n
( acฺ
d AC
Vi no
Table of Contents

Practices for Lesson 1 .....................................................................................................................................1-1


Practices for Lesson 1: Introduction to Oracle Fusion and Oracle ADF .........................................................1-3

Practices for Lesson 2 .....................................................................................................................................2-1


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Practices for Lesson 2: Getting Started with JDeveloper – Discovering the Shopping Cart Application ........2-3
Practice 2-1: Setting IDE Preferences............................................................................................................2-4
Practice 2-2: Creating a JDeveloper Application and Project .........................................................................2-6
Practice 2-3: Initializing the Project and Creating a Database Connection ....................................................2-8
Practice 2-4: Examining the Course Application ............................................................................................2-10

Practices for Lesson 3 .....................................................................................................................................3-1


Practices for Lesson 3: Building a Data Model with ADF Business Components ..........................................3-3
Practice 3-1: Creating Default Business Components ...................................................................................3-4
u se
Practice 3-2: Testing the Business Model ......................................................................................................3-8
e to
n s
ce
Practices for Lesson 4 .....................................................................................................................................4-1
i
b l el
Practices for Lesson 4: Querying and Persisting Data ...................................................................................4-3

r a
Practice 4-1: Creating Read-Only View Objects.............................................................................................4-4
fe
a n s
Practice 4-2: Creating Multiple Read-Only View Objects at Once ..................................................................4-7

n - tr
Practice 4-3: Creating Entity Objects Based on Database Views...................................................................4-9

a no eฺ
Practice 4-4: Creating Multiple Entity Objects at Once...................................................................................4-11
Practice 4-5: Creating Associations ...............................................................................................................4-12
h a s uid
Practice 4-6: Creating Updatable View Objects .............................................................................................4-14
m ) nt G
Practice 4-7: Refactoring Associations and Links ..........................................................................................4-17
l ฺ o
c tude
a i
Practices for Lesson 5 ........................................................................................................
S .............................5-1
g
Practices for Lesson 5: Exposing mData tois
Clients...........................................................................................5-3
Practice 5-1: Creatingoan@ApplicationtModule h to Display Categories .............................................................5-4
i n
( a c v an Application Module to Display the Shopping Cart ..................................................5-5
Practice 5-2: ฺCreating

C for Lesson 6 .....................................................................................................................................6-1


Practices
APractices
no d for Lesson 6: Declaratively Customizing Data Services .................................................................6-3

Vi Practice 6-1: Defining Control Hints ...............................................................................................................6-4


Practice 6-2: Declaratively Populating a Primary Key with a Database Sequence.........................................6-7
Practice 6-3: Designating History Columns ....................................................................................................6-9
Practice 6-4: Creating and Using View Criteria ..............................................................................................6-12
Practice 6-5: Creating Join View Objects .......................................................................................................6-15
Practice 6-6: Creating LOVs ..........................................................................................................................6-18

Practices for Lesson 7 .....................................................................................................................................7-1


Practices for Lesson 7: Programmatically Customizing Data Services ..........................................................7-3
Practice 7-1: Adding Code to Entity Objects ..................................................................................................7-4
Practice 7-2: Programmatically Assigning a Database Sequence..................................................................7-7
Practice 7-3: Populating History Columns When There Is No Logged-in User ..............................................7-9
Practice 7-4: Creating and Running a Test Client ..........................................................................................7-11
Practice 7-5: Creating an Application Module Base Class .............................................................................7-14
Practice 7-6: Editing an Application Module to Extend the New Base Class ..................................................7-17
Practice 7-7: Adding and Exposing Service Methods.....................................................................................7-18
Practice 7-8: Restrict the Shopping Cart Query .............................................................................................7-21

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Oracle Fusion Middleware 11g: Build Applications with ADF I Table of Contents
i
Practices for Lesson 8 .....................................................................................................................................8-1
Practices for Lesson 8: Validating User Input ................................................................................................8-3
Practice 8-1: Adding Declarative Validation: List Validator .............................................................................8-4
Practice 8 -2: Adding Declarative Validation: Unique Key Validator ...............................................................8-7
Practice 8-3: Adding Programmatic Validation: Method Validator ..................................................................8-9
Practice 8-4: Creating and Using a Domain for Validation .............................................................................8-12
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Practice 8-5: Testing the Validation................................................................................................................8-14

Practices for Lesson 9 .....................................................................................................................................9-1


Practices for Lesson 9: Troubleshooting ADF BC Applications ......................................................................9-3
Practice 9-1: Discovering Application Problems .............................................................................................9-4
Practice 9-2: Setting Breakpoints in the Debugger.........................................................................................9-5
Practice 9-3: Running the Application Module in Debug Mode ......................................................................9-7

Practices for Lesson 10 ...................................................................................................................................10-1


Practices for Lesson 10: Understanding UI Technologies ..............................................................................10-3 u se
e to
s
Practices for Lesson 11 ...................................................................................................................................11-1
n
Practices for Lesson 11: Binding UI Components to Data .............................................................................11-3
i ce
l el
Practice 11-1: Creating Databound Pages .....................................................................................................11-4
b
r a
Practice 11-2: Examining the Page's Data Bindings ......................................................................................11-8
fe
a n s
Practice 11-3: Adding an Additional Detail Table ...........................................................................................11-11

n - tr
Practice 11-4: Renaming a Page ...................................................................................................................11-13

a no eฺ
Practices for Lesson 12 ....................................................................................................... ............................12-1

ha t Guis d
Practices for Lesson 12: Planning the User Interface ....................................................................................12-3
Practice 12-1: Creating an Unbounded Task Flow ) .........................................................................................12-4
Practice 12-2: Creating Bounded Task Flows
l ฺ c om e n
................................................................................................12-10
d
Practice 12-3: Extracting Part of aa i tu
g m Task Flow s
................................................................................................12-16
S
Practices for Lesson 13@
o thi
.......................................................................................................
............................13-1
i n
cฺvCreating a Table with Row Selection ......................................................................................13-4
Practices for Lesson 13: Adding Functionality to Pages ................................................................................13-3
Practice a
13-1:
(
C 13-2: Creating a Search Page ..........................................................................................................13-10
d APractice
Vi no Practice 13-3: Creating a Read-Only Form ....................................................................................................13-16
Practice 13-4: Creating a Sortable Table .......................................................................................................13-18
Practice 13-5: Creating a Category Tree ........................................................................................................13-20
Practice 13-6: Creating LOVs ........................................................................................................................13-24
Practice 13-7: Setting Up the UI Project for Internationalization ....................................................................13-28

Practices for Lesson 14 ...................................................................................................................................14-1


Practices for Lesson 14: Implementing Navigation on Pages ........................................................................14-3
Practice 14-1: Creating Buttons for Navigation ..............................................................................................14-4
Practice 14-2: Creating Links for Navigation ..................................................................................................14-9
Practice 14-3: Using Breadcrumbs.................................................................................................................14-18
Practice 14-4: Defining a Sequence of Steps .................................................................................................14-19
Practice 14-5: Simplifying and Enhancing a Task Flow..................................................................................14-26

Practices for Lesson 15 ...................................................................................................................................15-1


Practices for Lesson 15: Achieving the Required Layout ...............................................................................15-3
Practice 15-1: Stretching Tables and Columns ..............................................................................................15-4
Practice 15-2: Adjusting JDeveloper's Default Layout Components ..............................................................15-6
Practice 15-3: Adding Layout Components to Existing Pages .......................................................................15-8

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Oracle Fusion Middleware 11g: Build Applications with ADF I Table of Contents
ii
Practice 15-4: Creating New Pages with Required Layout .............................................................................15-12
Practice 15-5: Setting Conditional Display .....................................................................................................15-20
Practice 15-6: Implement PPR to Coordinate Products Display with Selected Subcategory .........................15-25

Practices for Lesson 16 ...................................................................................................................................16-1


Practices for Lesson 16: Ensuring Reusability ...............................................................................................16-3
Practice 16-1: Converting Bounded Task Flows to Use Page Fragments ......................................................16-4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Practice 16-2: Creating a Page Template and Applying It to Existing Pages .................................................16-7
Practice 16-3: Creating a Page Template and Applying It to a New Page .....................................................16-13
Practice 16-4: Using Bounded Task Flows as a Region on a Page ...............................................................16-20

Practices for Lesson 17 ...................................................................................................................................17-1


Practices for Lesson 17: Passing Values Between UI Elements ....................................................................17-3
Practice 17-1: Conditional Rendering Based on Parameters .........................................................................17-4
Practice 17-2: Using Parameters for Dynamic Breadcrumbs .........................................................................17-11
Practice 17-3: Implementing the Add to Cart Functionality ............................................................................17-13 u se
Practice 17-4: Implementing Create Supplier Functionality (Optional) ...........................................................17-17
e to
n s
l i ce
Practices for Lesson 18 ...................................................................................................................................18-1

r a ble
Practices for Lesson 18: Responding to Application Events ..........................................................................18-3
Practice 18-1: Defining Task Flow Parameters ..............................................................................................18-4
s fe
Practice 18-2: Creating a Helper Method to Evaluate EL ...............................................................................18-5
n
n - tra
Practice 18-3: Creating the Producer (Payload) Method ................................................................................18-9

a no eฺ
Practice 18-4: Initiating the Contextual Event ................................................................................................18-12
Practice 18-5: Creating the Consumer (Handler) Method ..............................................................................18-14
h a s uid
Practice 18-6: Mapping the Contextual Event ................................................................................................18-16
Practice 18-7: Passing Values Through Region m Parameters
G
) nt.........................................................................18-19
Practice 18-8: Modifying the JSF LifeilCycle
o
ฺc (Optional e
dExercise) ...................................................................18-21
a t u
g m is S
Practices for Lesson 19 ...................................................................................................................................19-1
Practices for Lessono @ t h
ฺ v in 19:theImplementing Transactional Capabilities ................................................................19-3

(
Practice
c Updating, Deleting, and Displaying
Practice 19-1:
a19-2: Saving Shopping Cart .......................................................................................................19-4
Details of Shopping Cart Items ........................................19-5
C
n o d APractice 19-3: Controlling Transactions in the CheckoutFlow ........................................................................19-12
V i Practice 19-4: Adding CRUD Functionality for Suppliers (Optional Exercise) ................................................19-13

Practices for Lesson 20 ...................................................................................................................................20-1


Practices for Lesson 20: Implementing Security in ADF BC Applications ......................................................20-3
Practice 20-1: Configuring the Application to Use ADF Security ....................................................................20-4
Practice 20-2: Defining Users in the Identity Store .........................................................................................20-7
Practice 20-3: Defining Enterprise Roles .......................................................................................................20-8
Practice 20-4: Implementing Security on Task Flows and Pages...................................................................20-11
Practice 20-5: Testing Application Authentication and Authorization .............................................................20-13
Practice 20-6: Implementing Entity Object Security .......................................................................................20-15
Practice 20-7: Testing Entity Object Security .................................................................................................20-17
Practice 20-8: Accessing Security Context Programmatically ........................................................................20-18
Practice 20-9: Conditionally Displaying a Component Based on User Role ...................................................20-20
Practice 20-10: Modifying the Hard-Coded Username to Use the API ...........................................................20-23

Practices for Appendix A ................................................................................................................................21-1


Practices for Appendix A ................................................................................................................................21-3
Practice A-1: Creating a Database Diagram with Existing Schema Objects ..................................................21-4
Practice A-2: Adding New Schema Objects ...................................................................................................21-8
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Oracle Fusion Middleware 11g: Build Applications with ADF I Table of Contents
iii
Practices for Appendix B ................................................................................................................................22-1
Practices for Appendix B: Deploying ADF BC Applications ............................................................................22-3
Practice B-1: Creating Deployment Profiles ...................................................................................................22-4
Practice B-2: Using a WebLogic Server Data Source ....................................................................................22-6
Practice B-3: Creating an Application Server Connection ..............................................................................22-9
Practice B-4: Deploying the Application from JDeveloper ..............................................................................22-10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Practice B-5: Deploying the Application from the WebLogic Server Administration Console .........................22-12

u se
e to
n s
i ce
b l el
fe r a
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Oracle Fusion Middleware 11g: Build Applications with ADF I Table of Contents
iv
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 1
n - r
Chaptern1o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 1


Chapter 1 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 1


Chapter 1 - Page 2
Practices for Lesson 1: Introduction to Oracle Fusion and Oracle
ADF
There is no practice for this lesson.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 1


Chapter 1 - Page 3
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 1


Chapter 1 - Page 4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 2
n - r
Chaptern2o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 2
Practices for Lesson 2: Getting Started with JDeveloper – Discovering
the Shopping Cart Application
Practices Overview
In the practices for this lesson, you start JDeveloper, set preferences for the IDE, and create a
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

JDeveloper application, project, and database connection. You then view the course application
in a browser and identify the functionality of the pages.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 3
Practice 2-1: Setting IDE Preferences
In this practice, you start JDeveloper and set general preferences on the IDE.
1. Start JDeveloper, using the Default role.

a. Double-click the desktop shortcut to start JDeveloper.


Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the Select Role dialog box, select the Default Role option and click OK.
c. In the Migrate User Settings dialog box, click No.
d. JDeveloper starts by displaying the Tip of the Day. Deselect the “Show tips at
startup” check box, and then click Close.
e. Close the Start page by clicking the X at the right of its tab. (The X is not visible until
you position the cursor over the tab.)
2. Set the global naming preferences for your ADF BC objects. Entity objects, view objects,
and application modules should, by default, have the suffixes EO, VO, and AM, u se
respectively, and should be created in the entity, uiview, and module packages, e to
n s
respectively.
i ce
a. From the JDeveloper menu, select Tools > Preferences > Business Components >
b l el
Object Naming.
fe ra
b. In the dialog box, set suffixes as follows:
a n s
Entity n - tr
no eฺ
EO
View Object VOa
h a s uid
Application Module ) AM G
ฺ c o m
d e nt
m ail Stu
o@g this
c ฺ vin
( a
A C
n o d
V i

c. Select Packages in the list at the left and set the following values:
Entity entity
View Object uiview
Application Module module

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
d. Click OK. a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 5
Practice 2-2: Creating a JDeveloper Application and Project
In this practice, you begin developing the Storefront application by creating an application and
project.
1. Create an application named Storefront in the oracle.fod.storefront package. Do
not use an application template. Create the initial project with the name StorefrontModel.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, click the New Application link.


b. On the Name page of the Create Application Wizard:
1) Enter Storefront as the application name.
2) Enter oracle.fod.storefront as the application package prefix.
3) Select Generic Application as the Application Template.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
4) Click o @
Next. th
a. i n
ฺv “Name your project” page of the wizard:
On the
(a c
1) Enter StorefrontModel as the project name.
A C
n o d 2) On the Project Technologies tab, shuttle ADF Business Components and
Vi Database (Offline) from the Available list to the Selected list. (This also selects
the Java technology.)
3) Click Finish.
b. Note that the Application Navigator displays your application and project.

c. Also, note that the application overview page, Storefront Overview, is open in the
editor. This page enables you to see all the aspects of your application at a glance, to
obtain related help, and to create new objects. You can spend some time exploring this
overview if you want to, but it is not used in these practices.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 6
When you have finished looking at the overview, close it by clicking the X on its tab.
(The X is not visible until you move the cursor over the tab.) If you want to display it
again, right-click a project and select Show Overview.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 7
Practice 2-3: Initializing the Project and Creating a Database
Connection
In this practice, you initialize the StorefrontModel project for business components. In the
process of doing so, you create a database connection to use for the business components.
You also add any libraries that it requires.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Initialize the StorefrontModel project for business components. This requires a database
connection, so create that as part of this initialization.
a. Double-click the StorefrontModel project (or right-click it and select Project
Properties).
b. In the Project Properties dialog box, select Business Components from the tree at the
left.
c. In the Business Components panel, select the Initialize Project for Business
Components check box.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
d. Click Create a new database connection no to the ฺright of the Connection field.
s abox:uid
e
e. a
In the Create Database Connection dialog
h tG
1) Supply the information inm the)table below.
Connection Namei l ฺ co tuden FOD
m a S
g
Connection Type this
o @ Oracle (JDBC)

ฺ in
vUsername fod (or follow the instructions given by
( a c your instructor if you are using a shared
A C database)
n o d
Vi Password fusion
Save Password Select the check box.

2) In the lower half of the page, Oracle (JDBC) Settings, leave the Driver field at its
default, thin, and enter the Host Name, JDBC Port, and SID as given to you by the
instructor if using a shared database, or localhost, 1521, and XE if using a local
XE database.
3) Click Test Connection. You should see that the Status box displays the word
Success!.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. Click OK to dismiss the Create Database Connection dialog box and return to the
Business Components page of the Project Properties dialog box.
g. Click OK to set the project properties and dismiss the Project Properties dialog box. u se
e to
h. Click Save All to save your work. You should get into the habit of frequently n s
i ce
saving your work.
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 9
Practice 2-4: Examining the Course Application
In this practice, you run the completed application and explore its functionality.
1. Open the Storefront-CompletedApp application in JDeveloper. There are several ways to
open an application.
a. If there is no open application currently, you can click the Open Application link in the
Application Navigator…
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
OR if there is an open application, you can invoke the drop-down application
l i ce list by
Navigator, and then selecting Open Application… r a ble
clicking the down arrow at the right of the application name in the Application

n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
i n
v Open on the JDeveloper menu toolbar…
OR ฺclick
C (ac
d A
n o
Vi
OR select File > Open from the JDeveloper main menu.

b. When you select to open a new application, a file dialog box enables you to navigate to
the directory where the application resides:
1) Navigate to your course’s \Labs directory and open the Storefront-
CompletedApp folder.
2) Select Storefront-CompletedApp.jws and click Open.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

The application opens in the Application Navigator. If requested to migrate the


application, execute the necessary steps to perform the operation.
u se
2. Open the main task flow for the application, which is adfc-config.
e to
a. The application contains two projects that are displayed on the first level of the n s
i ce
application’s hierarchy. Expand the StorefrontUI node.
b. In the StorefrontUI project, expand the Web Content and Page Flows nodes. b l el
fe ra
c. Double-click adfc-config to open it in the editor.
a n s
3. tr
When a task flow opens in the editor, you will see a Thumbnail tab to the left of the editor,
n -
a no eฺ
below the Application Navigator. Click the Thumbnail tab, and then drag the viewport
rectangle so that the view activities are visible in the editor.
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 11
4. Examine the connection information and change it if necessary to point to your database.
a. Right-click the StorefrontModel project and select Project Properties. (You can also
double-click StorefrontModel to display the Project Properties Editor.)
b. Select Business Components in the tree at the left.
c. Next to Connection, click Edit.
d. Edit the connection information to your database connection (FOD) (see Practice 2-3,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

step 1(e)).
e. Test the connection, and if successful, click OK.
f. Click OK to close the Project Properties Editor and save the settings.
5. To run the application, in the adfc-config diagram, right-click the
FODShoppingDashboard view and select Run. Test the functionality of the shopping
application.
a. JDeveloper starts an integrated Oracle WebLogic Server, deploys the application to it,
and runs the requested page in a browser. A tree of categories appears at the left, with u se
a table of categories and descriptions at the right. In the tree, expand the Media e to
category and click the Music subcategory. n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
b. A list of Music h
o@productstappears in the right panel. Note that there are breadcrumbs
alongฺ v i
then top of the table that enable you to navigate to the Media subcategory, or to
a c
(the main-level list of categories if you click Store. For now, click the name of one of
A C the products.
n o d
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 12
c. Details about the selected product are shown. Buttons enable you to add the item to
your cart, to search for products, or to return to the shopping page. For now, click
Search.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

d. On the Search page, enter Pla in the ProductName field and click Search. A list of u se
products beginning with Pla is returned.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
e. g maPortable
Click the Playstation i s Slink to display details about this product.
o@ t h
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 13
f. Click Add Item to Cart to add the Playstation Portable to the shopping cart and display
the cart.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

g. The shopping cart is displayed. It is populated with the shopping cart items of a default
user, and the Playstation Portable has been added. Resize the right panel of the page
so that the line total is visible, and then change the quantity of the Playstation Portable
to 2. Click Update to show the updated line total.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
h. With the Playstation Portable selected, click
o toฺ remove it from your cart.
nDelete
s a i d e
a
) h nt G u
m
co tude
i l ฺ
g ma is S
o@ th
ฺv i n
(ac
d AC
Vi no i. Click Details to display details about the selected product in a separate pop-up
window.

j. Click OK to close the pop-up window, and then click Checkout to begin the checkout
process.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 14
k. The first page of the checkout process displays the shipping information. Navigate to
the next page either by clicking Next or by clicking the Billing train stop at the top of
the panel.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
l. ce to
The second page of the checkout process displays the billing information.liNavigate

top of the panel. r a b e stop at the


the next page either by clicking Next or by clicking the Confirmation ltrain

n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 15
m. The final page of the checkout process displays all the information—shipping, billing,
and order items. Click Submit to submit the order and return to the shopping page.
Note: The Submit button does not actually do anything except perform navigation, but
in a complete application, it could fire off some additional services, such as creating an
order in the database, sending information about the order to the shipping department
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

and the billing department, and sending an email confirmation to the customer. This
functionality is outside the scope of the course application.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
6. Test the functionality of a i S
g mmanaging i s suppliers.

i n o@ tabtinh the left panel of the page.


a. Click the Suppliers
v
( acฺ
d AC
Vi no

b. The page displays a list of suppliers. Click New Supplier.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 16
c. The New Supplier page initializes. Enter any supplier name and select a supplier status
from the drop-down list, and then click Save.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

d. The new row appears at the top of the list, with a supplier ID that is automatically
assigned. Click Delete to delete the supplier.

u se
e to
n s
i ce
b l el
fe ra
a n s
e. - tr
Click the SupplierId of one of the suppliers in the list.
n
f.
a no eฺ
On the Update Supplier page, change the Status of the supplier and click Save.

h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d g. The supplier is shown in the list with the updated status.
V i

h. Close the browser when you have finished.


i. To make the application start a little faster the next time you run it, you can undeploy
the application:
1) Select View > Run Manager.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 17
2) In the Run Manager window, select Storefront-CompletedApp (Running on
IntegratedWebLogicServer), and then click the red square to undeploy.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Another way to undeploy the application is to click Terminate in the JDeveloper


menu toolbar, and then select the application to undeploy.

u se
e to
j. The application is undeployed when the log window displays the message: [Application n s
i ce
Storefront-CompletedApp stopped and undeployed from Server Instance Instance
IntegratedWebLogicServer]. b l el
7. Close the Storefront-CompletedApp application. You should continue to work in the fe ra
Storefront application that you created. a n s
n - tr
a. Invoke the application menu by clicking the right-most down arrow at the top of the
Application Navigator. a no eฺ
a
b. Select Close Application from the IDE.
h s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 2


Chapter 2 - Page 18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 3
n - r
Chaptern3o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 2
Practices for Lesson 3: Building a Data Model with ADF Business
Components
Practices Overview
This exercise is to familiarize you with the default capabilities of JDeveloper and ADF Business
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Components.
In this practice, you create a business model by using the wizards that are built into JDeveloper.
You see how to build a default model without any coding. In subsequent lessons and practices,
you learn to build and customize components to meet your specific application requirements.
If you successfully completed all sections of the previous practice, you can continue working in
the same project. However, if you prefer to start with a clean application that contains everything
completed up to the start of this lesson, open Storefront-03.jws and edit the database
information as described in step 4 of Practice 2-4.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 3
Practice 3-1: Creating Default Business Components
In this practice, you create some default business components that compose part of the
business model for the Storefront application. In the practices for subsequent lessons, you
create more customized business components and refine the default components as well.
1. Invoke the Business Components Wizard.
a. Right-click the StorefrontModel project in the Application Navigator and select New.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Select Business Tier > ADF Business Components in the Categories list.
c. Select Business Components from Tables in the Items list.
d. Click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i
2. In the “Create Business Components from Tables” Wizard, create entity objects for the
ORDERS, ORDER_ITEMS, and PERSONS tables. Name them OrderEO, OrderItemEO, and
PersonEO.
a. On the Entity Objects page of the wizard, ensure that the schema from the connection
that you created previously is the selected schema.
b. Ensure that the package name is oracle.fod.storefront.entity.
c. Enter ORD in the Name Filter field. Click Query to see the available tables (ORDERS
and ORDER_ITEMS).

d. Click Add All to move both tables to the Selected pane.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 4
e. Select ORDERS in the Selected pane and change the Entity Name to OrderEO
(instead of OrdersEO).
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. Similarly, change the Entity Name of OrderItemsEO to OrderItemEO. u se


g. Set the Name Filter to % and click Query to show all the available tables. If you were e to
creating several more entity objects, you could multiselect any tables for which you n s
i ce
want to create EOs and shuttle them to the Selected pane at the same time. For now,
just create one additional EO, PersonEO, based on the PERSONS table. Be sure to b l el
change the default name of the entity object. fe ra
h. Click Next. a n s
n - tr
3.
no eฺ
Continuing in the “Create Business Components from Tables” Wizard, create the following
a
updatable view objects (do not create any read-only view objects at this time):
h a s uid
VO Based ) nt G on
ShoppingCartVOฺco
m e OrderEO
i l t u d
g ma is S
ShoppingCartItemVO OrderItemEO
t h
o@ View Objects page of the wizard, ensure that the package name is
a. n
On theiUpdatable
ฺv
(ac
oracle.fod.storefront.uiview.

A C
n o d
Vi b. Ctrl-click to select the OrderEO and OrderItemEO entities.

c. Click Add to move the selected items to the Selected list.


d. Rename OrderVO by selecting it in the Selected pane and changing the Object Name
to ShoppingCartVO. The reason for this is that you are creating a model for a
shopping application, where an order is represented as a customer’s shopping cart.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 5
e. Similarly, rename OrderItemVO to ShoppingCartItemVO.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
f. Click Next.
n s
g. The next page is for creating read-only view objects. These are based on SQL queries i ce
rather than on entity objects. For now, you will not create read-only VOs, so click Next. b l el
4. Continuing in the “Create Business Components from Tables” Wizard, create an applicationfe ra
n
module to provide access to your components. You will later create application modules
a s
- tr
that are customized for your application, but you can use a default application module for
n
no eฺ
testing your components. Create an application module named TestAM in the
a
oracle.fod.storefront.test package.
h a s uid
a.
check box is selected. ฺco
m ent G ensure that the Application Module
On the Application Module page )of the wizard,

b. To separate this test a


application
ud from those that you customize for the
il Stmodule
g m change is the package name to
Storefront application,
@ t h
ฺ v ino
oracle.fod.storefront.test.
c.
(a c the application module name to TestAM.
Change

d AC
i n o
V

d. Click Next.
5. Complete the wizard to finish creating the business components. Do not create a business
components diagram.
a. On the Diagram page of the wizard, ensure that the Business Components Diagram
check box is not selected.
b. Click Next.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 6
c. The last page of the wizard shows the components that you have chosen to create. It
should show the following components to be created:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
d. Click Finish to create the business components. This may take a few moments. n s
i ce
e. Click Save All to save your work.
b l el
f. The StorefrontModel project in the Applications Navigator should look like this:
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Note that the wizard created not only EOs, VOs, and an AM, but also two associations
and a view link based on the foreign key relationships that are defined in the database.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 7
Practice 3-2: Testing the Business Model
In this practice, you examine and test the components you just created.
1. Use the editor to examine the OrderEO entity object.
a. In the Applications Navigator, double-click the OrderEO entity to open the entity in the
editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Click the Attributes tab or panel to see the attributes. From this view, you can double-
click any of the attributes to open the Attribute Editor.
c. Each of the other panels (General, Business Rules, Java, Business Events, and View
Accessors) shows different aspects of the OrderEO entity. Click and examine each
panel.
d. Click the Source tab at the bottom of the editor to view and examine the XML source.
2. Test the default components by running the application module in the Business
Components Browser.
u se
a. In the Application Navigator, right-click the application module (TestAM) in the
e to
oracle.fod.storefront.test package and select Run.
n s
b. The Business Components Browser may take a few minutes to appear, and l i citemay
appear behind other windows. You can click its icon bleto display it.
on the taskbar
r a
n s fe can be in a
The Browser should initially look similar to the following (the objects
different order):
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi c. Under the ShoppingCart1 node, double-click the OrderItemsOrdersFkLink1 to open
a page that shows the order items that belong to an order. Because this is a shopping
application, an order is contained in a shopping cart and order items are referred to as
shopping cart items.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
d. In the top portion of the page, click Move to the next row to navigate through rowsto
in the Orders view. Note that the order items change as you move to a new order. n s e
e. Open the other views and examine the contents as you choose. l i ce
f. When you have finished, close the Business Components Browser.
r a ble
n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 9
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 3


Chapter 3 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 4
n - r
Chaptern4o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 2
Practices for Lesson 4: Querying and Persisting Data
Practices Overview
In the previous set of practices, you used the “Create Business Components from Tables”
Wizard to create multiple types of objects at once. You performed some limited customization of
components as enabled by the wizard, such as changing default names and locations.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Now you begin to create components that are more customized for your application. First you
determine the LOVs that your application requires, and you create read-only view objects to
support those LOVs. Next you create entity objects for tables that the application will update,
and you also create updatable view objects based on these. You also create and refactor
associations and view links. For now, you place all of the view objects and links in the TestAM
application module so that you can test them; in the next set of practices, you create custom
application modules that are designed for your application.
If you successfully completed all sections of the previous practice, you can continue working in
u se
the same project. However, if you prefer to start with a clean application that contains everything
e to
completed up to the start of this lesson, open Storefront-04.jws and edit the database
n s
information as described in step 4 of Practice 2-4. i ce
This practice contains some optional steps that are similar to steps already done. If you want to b l el
build the entire application yourself, you can complete the optional steps. However, in the fe ra
n s
interest of time, you may want to skip them. If you do so, you must begin the practices for the
a
- tr
next lesson by opening the starter application for that lesson.
n
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 3
Practice 4-1: Creating Read-Only View Objects
Most of the view objects in your application are required for updating information. However,
some view objects exist only to provide data for lists of values. In this practice, you create
read-only view objects to support LOVs.
Because these read-only view objects are based on SQL queries, you do not require an existing
entity object on which to base them. You create them by using either of two wizards:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

• Create View Object Wizard: Creates view objects individually; you must write the query
• Business Components from Tables Wizard: Creates multiple view objects at once; you
select the table for the query that is automatically generated
1. Create a single read-only view object to query the LOOKUP_CODES table by using a bind
variable for LOOKUP_TYPE. Name the view object LookupCodeVVO. Create it in the
oracle.fod.storefront.view package. Put the view object in your TestAM
application module. Use the following query statement for the VO: (You can copy the code
from LookupCodes.txt in the \files subdirectory of your \labs directory for this u se
course.) e to
n s
i ce
el
SELECT
LOOKUP_CODES.LOOKUP_TYPE LOOKUP_TYPE,
a b l
LOOKUP_CODES.LOOKUP_CODE LOOKUP_CODE, fe r
a n s
LOOKUP_CODES.MEANING MEANING,
n - tr
no eฺ
LOOKUP_CODES.DESCRIPTION DESCRIPTION,
a
LOOKUP_CODES.LANGUAGE LANGUAGE
h a s uid
FROM
m ) nt G
LOOKUP_CODES
l ฺ o
c tude
i
WHERE
g ma is S
@ th
LOOKUP_CODES.LANGUAGE = SYS_CONTEXT('USERENV', 'LANG') AND

ฺ v ino
LOOKUP_CODES.LOOKUP_TYPE = :BindLookupType
a. In c
a the Application Navigator, right-click the StorefrontModel project and select New
C (from the context menu.
d A
i n o b. In the New Gallery, expand the Business Tier node in the Categories list and select
V ADF Business Components. Select View Object in the Items list and click OK.
c. On the Name page of the Create View Object Wizard:
1) Change the package name to oracle.fod.storefront.view and enter
LookupCodeVVO as the view object name. (Note that the suffix is VVO rather
than VO that you used for the updatable view objects, and that you are placing the
read-only VOs in a separate package.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 4
2) Specify that the view object should have Read-only access through SQL query.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

3) Click Next. u se
d. On the Query page of the wizard: e to
n s
1) Enter the query statement shown in step 1. (You can copy from
i ce
LookupCodes.txt, or click Query Builder to build the query if desired, but make
b l el
sure that the finished query is as shown above.)
fe ra
2) Click Test to verify that the query is valid.
a n s
3) Click Next. n - tr
e. no eฺ
On the Bind Variables page of the wizard:
a
1) Click New.
h a s uid
m ) nt G
2) On the Variable tab in the lower section of the page, enter BindLookupType as
l ฺ o
c tude
the name for the variable, leaving all other values at their defaults.
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

3) Click Next.
f. Continue clicking Next until you reach the Application Module page:
1) Select the Application Module check box.
2) Click Browse next to the Package field.
3) Click the Hierarchy tab in Package Browser and browse to and select the oracle
> fod > storefront > test package. Click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 5
4) If the Name field is not automatically populated with TestAM:
a) Click Browse next to the Name field.
b) In the Select Parent dialog box, expand oracle > fod > storefront > test.
c) Select the TestAM application module to enable you to test the query.
5) Click Finish to create the view object. The Application Navigator should look
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

similar to the following screenshot:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
g. Save your work. a no eฺ
2. Test the query: h a s uid
m
a. Run TestAM as you did previously.
) nt G
l ฺ o
c Browser,
d edouble-click the LookupCodeV1 node.
i
b. In the Business Components t u
g madialogisbox,
c. In the Bind Variables
S enter a Value such as SHIPPING_CLASS_CODE and
click OK. o@ t h
i n
( a cฺv through the rows to see all the payment type codes. Note that all fields are
d. Navigate

A C disabled, because this view object is read-only.


Vi nod e. Click Edit Bind Variables to invoke the Bind Variables dialog box to modify the
value. You can enter different values for bind variables to test whatever lookup codes
you want to check from the following lookup types:
SHIPPING_CLASS_CODE USAGE_TYPE_CODE
CONTACT_METHOD_CODE PRODUCT_STATUS_CODE
OWNER_TYPE_CODE PERSON_TITLE_CODE
DISCOUNT_TYPE_CODE CARD_TYPE_CODE
PERSON_TYPE_CODE MEMBERSHIP_TYPE_CODE
GENDER_CODE ORDER_STATUS_CODE
MARITAL_STATUS_CODE ID_TYPE_CODE
VERIFICATION_METHOD_CODE SUPPLIER_STATUS_CODE
PAYMENT_TYPE_CODE

f. When you have finished testing, close the Business Components Browser.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 6
Practice 4-2: Creating Multiple Read-Only View Objects at Once
In this practice, you use the “Create Business Components from Tables” Wizard to create
multiple read-only view objects at once.
1. Create the following read-only view objects (note the VVO suffix) in the
oracle.fod.storefront.view package:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Query Table or View VO


COUNTRY_CODES CountryVVO
PERSONS CustomerVVO
PAYMENT_OPTIONS (optional) PaymentOptionVVO
PRODUCTS (optional) ProductVVO
WAREHOUSES (optional) WarehouseVVO
u se
Note: Creating all of these view objects is optional. You can create them all if you e to
want to, but you may choose to create only the first two. If you create only a n s
i ce
subset of the objects, you must begin the practices for the next lesson by opening
the starter application. b l el
a. As you did in Practice 3-1, step (1), invoke the Create Business Components from fe ra
Tables Wizard. a n s
n - tr
b. Click Next to navigate to the Read-Only View Objects page of the wizard:
a no eฺ
1) Set the package name to oracle.fod.storefront.view.
h a s uid
2) Select your schema (FOD) from ) ndrop-down
the G list.
3) Use the Name Filter, c m
orosimply click
t
e Query, to find and select the tables and views
i l ฺ t u d
g ma is S
shown above and modify the name in each case as before (note the VVO suffix).

o@ th
ฺv i n
C (ac
d A
n o
Vi

4) Click Next.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 7
c. On the Application Module page of the wizard, place the view objects in your
application module as you did before by using the Browse buttons to navigate to, and
select the proper package (test) and application module (TestAM).
d. Click Finish to create the view objects.
e. Save your work. The Application Navigator should look like this:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 8
Practice 4-3: Creating Entity Objects Based on Database Views
Although it is easy to create multiple EOs at once with the “Create Business Components from
Tables” Wizard, there are cases where you may want to use the Create Entity Object Wizard to
create EOs individually, because that enables a greater degree of customization at the time of
creation.
This application has some EOs that are based on database views, and it is necessary to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

designate a primary key for such EOs. You can do that with the Create Entity Object Wizard.
In this practice, you create several database view–based entity objects and designate their
primary keys.
1. Create an entity object named ProductCategoryEO and base it on the
Product_Categories database view. Set the CategoryId to be its primary key.
a. To invoke the Entity Object Wizard, you could use the New Gallery. However, there is
an even easier way to invoke the wizards:
1) In the Application Navigator, expand the StorefrontModel project. u se
e to
2) Expand the Application Sources and oracle.fod.storefront nodes.
n s
3) Right-click the entity node and select New Entity Object. i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
b. i
On the Name page ofathe Create S Entity Object Wizard:
g m i s
1) Ensure @
o th
that oracle.fod.storefront.entity is the package name.
i n
v ProductCategoryEO as the entity object name.
2) ฺEnter
a c
(3) Ensure that the Database Schema Object option is selected and that the
A C database schema is FOD.
n o d
Vi 4) Click Browse to the right of the Schema Object field.
a) In the Select Schema Object dialog box, select the Views object type and
deselect Tables.
b) Click Query.
c) In the list of schema objects, select PRODUCT_CATEGORIES. Note that you
cannot multiselect more than one schema object, because you are creating
only one entity object with this wizard.
d) Click OK.
5) If the schema object is not automatically populated in the field, enter
PRODUCT_CATEGORIES. Click Next.
c. On the Attributes page, click Next to accept all columns. This wizard enables you to
remove or add attributes if necessary.
d. On the Attribute Settings page:
1) Select CategoryId from the Select Attribute drop-down list.
2) Select the Primary Key check box.
3) Click Finish to create your ProductCategoryEO entity object.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 9
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
2. n - tr
Optional step (If you choose not to create these objects, you must begin the
no eฺ
practices for the next lesson by opening the starter application.)
a
a s uid
Similarly, create the following entity objects that are based on database views:
h
EO o m
Based e n t G View
) on Database Primary Key
a ilฺc PERSON_INFORMATION
S t u d
gm thisPRODUCTS
PersonInformationEO CustomerId
ProductEO @
ino
ProductId
ฺ v
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 10
Practice 4-4: Creating Multiple Entity Objects at Once
You can create entity objects individually as above, but it is much quicker to create multiple
entity objects if you do not have to specify the columns to include or change attribute settings
(such as setting the primary key). In this practice, you create the remaining entity objects at
once by using the Business Components from Tables Wizard.
1. Create the following entity objects that are based on tables:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

EO Based on
AddressEO ADDRESSES
AddressUsageEO ADDRESS_USAGES
CountryEO COUNTRY_CODES
LOOKUP_CODES
se
LookupCodeEO
PaymentOptionEO PAYMENT_OPTIONS to u
SUPPLIERS n s e
ce
SupplierEO
WAREHOUSES eli
WarehouseEO
a b l
WarehouseStockLevelEO WAREHOUSE_STOCK_LEVELS fe r
a n s
n - tr
Note: Creating all of these entity objects is optional. You can create them all if you

a no eฺ
want to, but you may choose to create only the first two. If you create only a
subset of the objects, you must begin the practices for the next lesson by opening
the starter application.
h a s uid
m ) nt G
a. In the Application Navigator, right-click the oracle.fod.storefront.entity package, and
l ฺ o
c tude
select New Business Components from Tables.
i
ma is S
b. On the Entity Objects page of the Business Components from Tables Wizard, check
g
@ th
whether the package name is oracle.fod.storefront.entity and the schema is
o
c ฺ vin
FOD. Click Query.
a
c. (As you did in an earlier practice, Ctrl-click to select multiple tables for which to create
C
A entity objects, and rename the entity objects, according to the table shown above.
n o d d. Click Finish to create the entity objects.
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 11
Practice 4-5: Creating Associations
When you use the Business Components from Tables Wizard to create entity objects, database
foreign keys are used to automatically generate associations. However, there are some
additional associations that you must create for the EOs that are based on database views, and
others that you must create where there are no foreign keys. In this practice, you create these
additional associations.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Create an association that relates CategoryId of the ProductCategoryEO entity object


to ParentCategoryId of the same entity object. Name the association
ProductCategoriesSubProductCategoriesAssoc.
a. Right-click the oracle.fod.storefront.entity package and select New Association.
b. On the Name page of the Create Association Wizard:
1) Ensure that the package is oracle.fod.storefront.entity.
2) Enter a name of ProductCategoriesSubProductCategoriesAssoc.
u se
3) Click Next.
e to
c. On the Entity Objects page of the wizard: n s
i ce
1) Expand ProductCategoryEO in the Select Source Attribute list and select the
CategoryId attribute. b l el
fe ra
a n s
2) Expand ProductCategoryEO in the Select Destination Attribute list and select the
ParentCategoryId attribute.
n - tr
3) Click Add, and then click Next.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

d. On the Association Properties page of the wizard:


1) Leave the check boxes selected in both Source Accessor and Destination
Accessor sections.
2) Click Next, and then click Finish.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 12
2. Optional step (If you choose not to create these associations, you must begin the
practices for the next lesson by opening the starter application.)
In a similar manner, create the following additional associations, with accessors in both
source and destination (leave both check boxes selected):
Name Source Destination
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

OrdersOrderItemsAssoc OrderEO.OrderId OrderItemEO.OrderId


ProductCategoriesProductsAssoc ProductCategoryEO. ProductEO.CategoryId
CategoryId
3. Optional step (If you choose not to create this association, you must begin the
practices for the next lesson by opening the starter application.)
In a similar manner, create an association named OrderItemsProductsAssoc between
the ProductId fields of the OrderItemEO and ProductEO entity objects. The application u se
needs to access the product for a particular order item, but never needs to access order e to
n s
items that pertain to a particular product, so expose accessors only in the destination
ice
entity for this association. (Deselect the check box in the Source Accessor section.)
b l el
4. Save your work. Including the optional steps, the entity package in the Application
fe ra
Navigator should now look like this:
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 13
Practice 4-6: Creating Updatable View Objects
In this practice, you create updatable view objects based on some of the entity objects you
created in previous practices. Because you are creating view objects that are based on existing
entity objects, you must use the Create View Object Wizard.
In the application that you are building, the user interface displays categories and
subcategories. To accomplish this, the model requires two view objects: one that displays the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

root categories (those without a parent category), and another that displays the subcategories.
A view link is also required to set up this master-detail relationship.
1. In the oracle.fod.storefront.uiview package, create two view objects that are based on
ProductCategoryEO: RootCategoryVO for those rows whose ParentCategoryId is null, and
SubCategoryVO. Place the view objects in your TestAM application module.
a. In the Application Navigator, right-click the oracle.fod.storefront.uiview
package and select New View Object from the context menu.
b. On the Name page of the Create View Object Wizard: u se
1) Ensure that the package is oracle.fod.storefront.uiview. e to
n s
2) Enter RootCategoryVO as the view object name.
i ce
3) Select the Updatable access through entity objects option.
b l el
4) Click Next. fe ra
c. On the Entity Objects page: a n s
n -
1) Expand the oracle.fod.storefront.entity package node.
tr
a no eฺ
2) Shuttle ProductCategoryEO into the Selected pane.
3) Click Next. h a s uid
m ) nt G
d. On the Attributes page:
l ฺ o
c tude
i
1) Click Add All g ma to shuttle
i s S all attributes into the Selected pane.
2) Click o @
Next. t h
e.
i n
ฺv Attribute Settings page, click Next.
On the
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 14
f. On the Query page:
1) Add the following WHERE clause:
ProductCategoryEO.PARENT_CATEGORY_ID IS NULL
2) Click Test to ensure that the query is valid, and click OK to acknowledge the
message.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
3) Click Next. a no eฺ
g. Navigate through the subsequent pagesh a suntil youu idreach the Application Module page:
1) Add the view object to them
o TestAM
e t G module as you have been doing.
) napplication
ilฺctheSupdatable
2) Click Finish to create
a t ud view object.
h. mSubCategoryVO
Similarly, creategthe is view object based on the same
o @
ProductCategoryEO t h
entity object, with all attributes.
i n
v the following WHERE clause:
1) ฺUse
(ac ProductCategoryEO.PARENT_CATEGORY_ID IS NOT NULL
d ACthe view object in your TestAM application module.
Place

Vi no 2. The two view objects that you just created should be related by
ProductCategoriesSubProductCategoriesAssoc in a view link named
RootCategoriesSubCategoriesLink. Create this view link.
a. Right-click the oracle.fod.storefront.uiview package and select New View Link.
b. On the Name page of the Create View Link Wizard, enter a name of
RootCategoriesSubCategoriesLink, and then click Next.
c. From the Select Source Attribute list, select oracle.fod.storefront.uiview >
RootCategoryVO > ProductCategoriesSubProductCategoriesAssoc.
d. From the Select Destination Attribute list, select oracle.fod.storefront.uiview >
SubCategoryVO > ProductCategoriesSubProductCategoriesAssoc.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 15
e. Click Add.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
f. Click Next several times until you reach the Application Module page. Select the
e to
Application Module check box and browse to select the TestAM application module n s
in the oracle.fod.storefront.test package. Click Finish to create the view link. i ce
3. Optional step (If you choose not to create this object, you must begin the practices b l el
for the next lesson by opening the starter application.) fe ra
Similarly, create one more updatable view object named SupplierVO in the a n s
n - tr
oracle.fod.storefront.uiview package. Base it on SupplierEO, including all
no eฺ
attributes. Do not include a WHERE clause. Add the view object to the TestAM application
a
module.
h a s uid
4. m ) nt G
Save your work, and then test the view objects and view link that you just created.
l ฺ o
c tude
a. Run TestAM as before. i
ma is S
b. Check whether the RootCategory1 view object instance displays the data you expect
g
@ th
(only those categories without a ParentCategoryId should display).
o
ฺ vin
c. Check whether the SubCategory1 view object instance displays the data you expect
c
( a(only those categories with a ParentCategoryId).
A C
d. Test that RootCategoriesSubCategoriesLink displays the master-detail relationship
n o d between root categories and subcategories, similar to the following:
V i

e. Close the Business Components Browser when you have finished testing.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 16
Practice 4-7: Refactoring Associations and Links
If you inadvertently create objects in the wrong package, or if you want to reorganize the
created objects into different packages, you can use refactoring. In this practice, you move
existing associations and links into a separate package.
1. Move all associations into the oracle.fod.storefront.assoc package.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, multiselect (Ctrl-click) all associations in the


oracle.fod.storefront.entity package.
b. Right-click and select Refactor > Move. Note that depending on the optional steps you
have or have not done, your application might look different from the following images.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
a
c. (In the Move Business Components dialog box, enter the Package name of
C
A oracle.fod.storefront.assoc and click OK.
n o d
V i

d. Confirm that you would like to create the package by clicking Yes.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 17
e. JDeveloper creates the assoc package and moves the associations into it. This may
take several minutes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
2. In a similar manner, move all viewmlinks G
) into nthet oracle.fod.storefront.link
o e
ilฺctheSuiview
package. Refactor links in both
a t ud and the view packages.
g m is
o@ th
v i n
( acฺ
d AC
Vi no

3. Test the application module to ensure that all view links still function correctly.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 4


Chapter 4 - Page 18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 5
n - r
Chaptern5o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 5


Chapter 5 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 5


Chapter 5 - Page 2
Practices for Lesson 5: Exposing Data to Clients
Practices Overview
In this practice, you take some of the view objects you have created and add them to application
modules. You create two application modules in this practice. The first application module
displays categories and subcategories. The second application module is for displaying and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

managing a customer’s shopping cart.


In the interest of time, you create only two of the five application modules that are required for
the Storefront application, although you have the knowledge to create all five. When you begin
to develop the user interface, you will start with a completed model with all the objects and
application modules that you require.
If you successfully completed all sections of the previous practice, including the optional steps,
you can continue working in the same project. However, if you prefer to start with a clean
application that contains everything completed up to the start of this lesson, open
u se
Storefront-05.jws and edit the database information as described in step 4 of Practice 2-4.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 5


Chapter 5 - Page 3
Practice 5-1: Creating an Application Module to Display Categories
In this practice, you create the application module to display categories. It contains the two VOs
that are based on ProductCategoryEO and the view link that establishes a master-detail
relationship between root categories and subcategories.
1. Create an application module named FODCategoryAM and put it in the
oracle.fod.storefront.module package. It should contain RootCategoryVO and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

also the VO for the subcategories, accessed through the view link.
a. Right-click the oracle.fod.storefront package and select New Application Module.
b. On the Name page of the Create Application Module Wizard, ensure that the package
name is oracle.fod.storefront.module. Enter the name FODCategoryAM and
click Next.
c. On the Data Model page, in the Available View Objects pane, expand
oracle.fod.storefront.uiview and RootCategoryVO.
d. Select RootCategoryVO and shuttle it to the Data Model. u se
e to
e. With RootCategoryVO1 selected in the Data Model panel, shuttle SubCategoryVO
n s
via RootCategoriesSubCategoriesLink to the Data Model. i ce
f. Click Finish to create the application module. b l el
g. Save your work. fe ra
2. Test the application module and then close the Business Components Browser when you a n s
have finished. n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 5


Chapter 5 - Page 4
Practice 5-2: Creating an Application Module to Display the Shopping
Cart
In this practice, you create the application module to display a customer’s shopping cart.
1. Create the shopping cart application module named FODShoppingCartAM in the
oracle.fod.storefront.module package. It should contain the VOs that are based
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

on Orders and OrderItems, with the view link.


a. Right-click the oracle.fod.storefront.module package and select New Application
Module.
b. On the Name page of the Create Application Module Wizard, enter the name
FODShoppingCartAM and click Next.
c. On the Data Model page, expand oracle.fod.storefront.uiview and
ShoppingCartVO.
d. Select ShoppingCartVO and shuttle it to the Data Model. u se
e. With ShoppingCartVO1 selected in the DataModel, shuttle ShoppingCartItemVO via
e to
OrderItemsOrdersFkLink to the Data Model. n s
i ce
f. Click Finish to create the application module.
b l el
g. Save your work.
fe ra
2. Test the application module and then close the Business Components Browser when you
a n s
have finished.
n - tr
a no eฺ
Note: At first, this application module shows all orders. In the practices for a later lesson,
you add code so that it displays the shopping cart (status CART order) for a particular user.
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 5


Chapter 5 - Page 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 5


Chapter 5 - Page 6
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 6
n - r
Chaptern6o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 2
Practices for Lesson 6: Declaratively Customizing Data Services
Practices Overview
In this set of practices, you make declarative modifications to your business components.
If you successfully completed all sections of the previous practice, you can continue working in
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

the same project. However, if you prefer to start with a clean application that contains everything
completed up to the start of this lesson, open Storefront-06.jws and edit the database
information as described in step 4 of Practice 2-4.
This practice contains some optional steps that are similar to steps already done. If you want to
build the entire application yourself, you can complete the optional steps. However, in the
interest of time, you may want to skip them. If you do so, you must begin the practices for the
next lesson by opening the starter application for that lesson.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 3
Practice 6-1: Defining Control Hints
Control hints on entity object attributes enable you to globally define labels, tool tips, and
formatting for any views that are based on those entity objects. In this practice, you define and
test several control hints.
1. In the OrderEO entity object, format the OrderTotal as currency and set the labels of
OrderTotal, OrderDate, and OrderShippedDate to have spaces between the words.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

You also set some tool tips.


a. In the Application Navigator, in the entity package, double-click OrderEO to open it in
the editor.
b. Click the Attributes tab at the left of the editor.
c. Select the OrderTotal attribute and click Edit . (You can also double-click the
attribute to open its editor.)
d. In the Edit Attribute dialog box, select Control Hints in the list at the left.
u se
e. Set the Format Type to Currency.
e to
f. Set the Label Text to Order Total by using a resource bundle (for translatable text), n s
i ce
as follows:
b l el
1) Click the ellipsis to the right of the Label Text field.
fe ra
2) In the Select Text Resource dialog box:
a n s
- tr
a) In the Display Value field, enter Order Total. This automatically populates
n
no eฺ
the Key field, but you could change the Key value if desired. However, you
a
h a s uid
can leave it at the default for this attribute.
) nt G
b) Enter the following in the Description field: Label for OrderTotal
m
attribute.
l ฺ o
c tude
i
ma andisSelect
c) Click the Save
g S button.
o@ th
ฺv i n
( ac
AC
d
V ino

g. Set the appropriate tool tip text, using a resource bundle.


1) Click the ellipsis to the right of the Tooltip Text field.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 4
2) In the Select Text Resource dialog box:
a) In the Display Value field, enter Computed total of the order, and in
the Key field, enter ORDER_TOTAL_TOOLTIP.
b) Enter the following in the Description field: Tooltip for the Order
Total attribute.
c) Click Save and Select.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
eto
n s
Note: Whether or not the instructions specifically direct you to do so, you
l i cethese
can use

a
practices, as you would need to do for a real application. However,
r blein the interest
a text resource in a resource bundle for any translatable text throughout

of time, you may choose to simply enter the hard-coded s e


ftext.
h. tra
Click OK to dismiss the attribute editor for OrderTotal.
n
n -
i. Optional step: Using a resource bundle, enter
a noappropriate
e ฺ Label Text and Tool tip
Text for OrderDate and OrderShippedDate. s uid For example:
h a
) nt G
o m
c tude
i l ฺ
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

2. Optional step: Similarly, edit OrderItemEO to format UnitPrice as Currency and set its
Label Text to have a space between words.
3. Test the changes by running TestAM in the oracle.fod.storefront.test package.
a. Double-click ShoppingCart1 > OrderItemsOrdersFkLink1.
b. Look at the labels and formatting that you defined.
c. Position the cursor over OrderTotal, OrderDate, and OrderShippedDate to see the
tool tip text.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
d. Close the Business Components Browser when you have finished. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 6
Practice 6-2: Declaratively Populating a Primary Key with a Database
Sequence
Declarative use of a database sequence to populate an EO attribute value relies on existence of
a database sequence and a database trigger to use that sequence. For example, the FOD
schema has a database sequence named SUPPLIER_SEQ and a database trigger that the DBA
created with the following script:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

CREATE TRIGGER ASSIGN_SUPPLIER_ID BEFORE INSERT ON SUPPLIERS


FOR EACH ROW
BEGIN
IF :NEW.SUPPLIER_ID IS NULL OR :NEW.SUPPLIER_ID < 0 THEN
SELECT SUPPLIER_SEQ.NEXTVAL
INTO :NEW.SUPPLIER_ID
FROM DUAL; u se
e to
END IF;
n s
END;
i ce
This ensures that when a new row is committed with a null primary key, the value from the b l el
database sequence populates the primary key. When you use a database trigger to populate
fe ra
n
the primary key, there are few gaps in the sequence of the primary keys, because the database
a s
sequence does not get used until the row is committed.
n - tr
no eฺ
On the Business Components model side, all that is required is to populate the value
a
h a s uid
temporarily, so that the NOT NULL primary key can be committed. That is what happens when
) nt G
you declaratively set the column to use a database sequence, as you do in this practice.
m
o
c tude
1. Set SupplierEO to use a database sequence at commit time for its primary key. There is
l ฺ
i
sequence if it is null.g ma is S
already a database trigger defined that populates the primary key from a database

o@ th
c ฺ vin
a. In the Application Navigator, double-click SupplierEO to open it in the editor.
b. Click the Attributes tab.
( a
C
A Select the SupplierId attribute and click Edit
c. .
d
V ino d. In the Edit Attribute dialog box, select Entity Attribute in the list at the left.
e. Select DBSequence from the Type drop-down list. (If not in the list, click Browse and
select it in the oracle.jbo.domain package.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 7
f. Make sure that the attribute has the following properties:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
Value 0 a no eฺ
While New h a s uid
Selected
m ) nt G
Persistent
l ฺ o e
c tudSelected
i
Primary Key
g ma is S Selected
Queryable o@ th Selected
i n
cฺv
Insert
(a Selected

d AC
g. Click OK.
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 8
Practice 6-3: Designating History Columns
There are several mandatory attributes in many of the entity objects that record information
about the record: who created it and when it was created, who last updated it and when it was
last updated, and a version number. These attributes can be automatically populated if you
designate them as history columns.
In this practice, you modify three of the entity objects so that the history columns are populated
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

automatically.
1. In the SupplierEO entity object, designate the following columns as history columns and
ensure that they are automatically populated at run time: CreatedBy, CreationDate,
LastUpdatedBy, LastUpdateDate, and ObjectVersionId.
a. In the Application Navigator, double-click SupplierEO to open it in the editor, or click
its tab if it is already open.
b. Click the Attributes tab.
u se
c. Select the CreationDate attribute and click Edit .
e to
d. In the Edit Attribute dialog box, select Entity Attribute in the list at the left. n s
i ce
e. Select the History Column check box and select created on from the drop-down list.
b l el
f. Click OK.
fe ra
g. s
Similarly, edit the following attributes by selecting the History Column check box and
a n
n - tr
choosing the following values from the drop-down list:

a no eฺ
h a s uid
Attribute Name
o m e n t GColumn value
) History
LastUpdateDate
a ilฺc Stud modified on
ObjectVersionIdg
m is
o @ th version number

c ฺ vin
h.
C (a
To populate the history columns for “created by” and “modified by,” there must be a
d A logged-in user. You later designate these attributes as history columns, but to test with
i n o the Business Components Tester with no logged-in user, you simply give these
V columns default values. Set the default Value of the CreatedBy and LastUpdatedBy
attributes to anonymous. (Ensure that Literal is selected as the option for Value Type.)

2. Optional step: (If you choose not to complete this step, you must begin the practices
for the next lesson by opening the starter application.)
Similarly, modify the same five attributes for OrderItemEO and for OrderEO.
3. Save your work.
4. Test SupplierVO to ensure that you can actually insert and commit a record.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 9
a. Run the TestAM application module.
b. Double-click Supplier1.

c. Click Insert .
d. Ensure that a temporary SupplierId appears (it should be a negative number) and that
the history columns are populated.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
e. Enter a SupplierName, such as ABC Plumbing, and a SupplierStatus, such as
fe ra
ACTIVE.
a n s
n - tr
f. Click Save .
a no eฺ
g.
h a s from
Ensure that the SupplierId value is populated
u idthe database sequence.
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi
5. Optional step: (Perform this step only if you added history columns to these entities.)
Test OrderEO and OrderItemEO, making sure that when you insert a record the history
columns are populated.
a. Double-click ShoppingCart1 > OrderItemsOrdersFkLink1.

b. In the upper section of the panel, click Insert .


c. Ensure that all five of the history columns are populated.

d. Click Insert in the lower portion.


e. Ensure that the history columns are populated in the new row.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
li ce
l e
b to delete the
f. Click Delete in the lower and then in the upper sections of the
e r apanel
new rows without committing them.
a n sf
g. Close the Business Components Browser when youthave
n - r finished.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 11
Practice 6-4: Creating and Using View Criteria
In this practice, you define a named query for the PaymentOptionVVO view object. Named
queries, referred to as view criteria, enable you to define complex sets of query criteria that you
can optionally apply at run time.
1. Add a named query to PaymentOptionVVO that selects records where CustomerId is
equal to a bind variable named PersonId.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, in the oracle.fod.storefront.view package, double-click


the PaymentOptionVVO view object to open it in the editor.
b. Click the Query tab to the left of the editor.
c. In the View Criteria section, click Add .

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
d. s theuCriteria
In the Create View Criteria dialog box, click
h a id Definition tab and click the
Add Item button.
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 12
e. In the Criteria Item section of the Create View Criteria dialog box, select the following
values from the drop-down lists:
List Name Value
Attribute CustomerId
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Operator Equal to
Operand Bind Variable
Parameter Click New and define a variable named
PersonId of type Number.
Validation Optional

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i
f. Click OK to create the named query.
2. Test the query by applying the view criteria in the Business Components Browser, using
values 110, 114, 117, or 119 for the bind variable.
a. Run TestAM in the Business Components Browser.
b. Double-click PaymentOptionV1.
c. In the PaymentOptionV1 window, click Specify View Criteria .
d. In the Business Component View Criteria dialog box, select
PaymentOptionVVOCriteria in the Available list and shuttle it to the Selected list, and
then click Find.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 13
e. In the Bind Variables dialog box, enter a value of 110 and click OK.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
f. The payment options for customer 110
h a sshould be
u iddisplayed.
g. You can test with other valuesmif )
you would
n G to do so. Some other valid values are
t like
114, 117, and 119. ilฺc
o d e
a t u
S Browser when you have finished testing.
h. Close the Business
g mComponents
i s
o@ t h
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 14
Practice 6-5: Creating Join View Objects
Join views are those that include more than one entity object. One serves as the basis for the
view object, whereas additional entity objects are for reference.
For example, the OrderEO contains information about an order, including the CustomerId,
whereas PersonEO contains information about persons, including customers. In the
ShoppingCartVO view object, you may want to display the customer name or other customer
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

information, which is part of PersonEO. To accomplish this, you can include PersonEO in the
view object as a reference entity, creating a join view.
You can create join views when using the Create View Object Wizard. If you already have a
view object to which you want to add a reference entity, you can do so by editing the view object
to create the join view. That is what you do in this practice.
1. Add all the attributes from PersonEO as an inner join to be used as reference in the
ShoppingCartVO view object.
a. In the Application Navigator, in the oracle.fod.storefront.uiview package, u se
double-click the ShoppingCartVO view object to open it in the editor. e to
n s
b. Click the Entity Objects tab to the left of the editor.
i ce
c. Expand oracle.fod.storefront.entity and shuttle PersonEO to the Selected list.
b l el
d. Select PersonEO in the Selected list. Ensure that the Association is set to fe ra
OrdersPersonsFkAssoc.Person and that the Join Type is set to inner join. Ensure
a n s
- tr
that the Updatable check box is not selected, and that the Reference check box is
n
selected.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

e. Click the Attributes tab to the left of the editor.


f. Check to be sure that all the attributes from PersonEO have been added to the VO.
1) If they have not been added automatically, click the down arrow next to the Add

icon and select Add Attribute from Entity to add them.


Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 15
2) In the Attributes Editor, select PersonEO in the Available list and shuttle it to the
Selected list—this adds all of its attributes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
3) Click OK. a no eฺ
h
2. Optional step: (If you choose not to createa s theseuobjects,
id you must begin the
practices for the next lesson by m
opening the
G application.)
) nt starter
o e
ilฺc andSattributes
Similarly, add reference entities
a t ud to ShoppingCartItemVO as follows:
Entity Object@g
m is
o th Attributes

ฺ vin
ProductEO
c ProductId
( a ProductName
A C
n o d Description

Vi AdditionalInfo
ListPrice
ProductCategoryEO CategoryId
CategoryName
a. In the Application Navigator, double-click the ShoppingCartItemVO view object in the
oracle.fod.storefront.uiview package to open it in the editor.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 16
b. Add the reference entities and attributes shown in the table above, accepting the
default join types. If all attributes are added automatically, delete all attributes that are
added except for those shown in the table above.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
3. Optional step: (Perform this step only
m ) if you
n G history columns to the
t added
ShoppingCartItemEO entity.): o
ฺc tud e
a
Delete the history attributes
ilfrom S
ShoppingCartItemVO. You do not need these mandatory
g m because i s
attributes in the view
o @ object th you have set their values in the entity object.
inalready open, double-click the ShoppingCartItemVO view object in the
a. If it isvnot

( a c
oracle.fod.storefront.uiview package of the Application Navigator to open it in the
C editor.
A b.
d Click the Attributes tab and delete the following attributes: CreatedBy,
V ino CreationDate, LastUpdatedBy, LastUpdateDate, and ObjectVersionId.
c. Save your work.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 17
Practice 6-6: Creating LOVs
When you define a list of values in the back-end data model, any UI that uses that model
displays the LOV automatically.
In this practice, you create a view accessor that supports a list of values for the ProductId in
the ShoppingCartItemVO. You then modify the ProductId to use an LOV.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. In OrderItemEO, create a view accessor to ProductVVO.


a. In the Application Navigator, double-click OrderItemEO in the
oracle.fod.storefront.entity package to open it in the editor.
b. Click the View Accessors tab at the left of the editor.
c. On the View Accessors panel, click Create new view accessors .
d. In the list of Available View Objects, expand oracle.fod.storefront.view.
e. Select ProductVVO and shuttle it to the View Accessors list, and then click OK.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i
f. Save your work.
2. In ShoppingCartItemVO, set ProductId to use a choice list as an LOV, and force users
to select a value from that LOV. Display the ProductId and ProductName in the LOV.
a. In the Application Navigator, double-click ShoppingCartItemVO in the
oracle.fod.storefront.uiview package to open it in the editor.
b. Click the Attributes tab to the left of the editor.
c. Select the ProductId attribute.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 18
d. Expand the List of Values section in the editor and click Add list of values .
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
a
e. (In the List of Values dialog box:
A C
n o d 1) On the Configuration tab:
V i a) Select OrderItemEO.ProductVVO1 as the List Data Source. (Click OK in
the Information dialog box.)
b) Select ProductId as the List Attribute.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 19
2) On the UI Hints tab:
a) Ensure that the Default List Type is Choice List.
b) Shuttle ProductId and ProductName to the Selected list; these are the
attributes that will appear in the list.
c) Deselect the Include “No Selection” Item check box.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
@ th
3)
ฺ v inoOK.
Click
( ac
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 20
3. Test the LOV.
a. Run the TestAM application module.
b. Double-click the first-level ShoppingCartItem1. You should see that ProductId
appears as a drop-down list that shows the ProductId and ProductName. Note the
OrderId value.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
c. Change the initial product to some other product.
a n s
d.
n - tr
Double-click OrderItemsOrdersFkLink1 under ShoppingCart1.
e. no eฺ
Query for the same order that appears in the ShoppingCartItem1 window (order 1034
a
s uid
in the example shown above). The corresponding shopping cart item should show the
h a
change that you made in the other window. View objects that display the same data
) nt G
o m
remain in sync throughout the application.
c tude
i l ฺ
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

f. Close the Business Components Browser.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 21
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 6


Chapter 6 - Page 22
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 7
n - r
Chaptern7o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 2
Practices for Lesson 7: Programmatically Customizing Data Services
Practices Overview
In this set of practices, you add programmatic functionality to your business components.
If you have successfully completed all sections of the previous practice, including the optional
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

steps, you can continue working in the same project. However, if you prefer to start with a clean
application that contains everything completed up to the start of this lesson, open
Storefront-07.jws and edit the database information as described in step 4 of Practice 2-4.
This practice contains some optional steps that are similar to steps already done. If you want to
build the entire application yourself, you can complete the optional steps. However, in the
interest of time, you may want to skip them. If you do so, you must begin the practices for the
next lesson by opening the starter application for that lesson.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 3
Practice 7-1: Adding Code to Entity Objects
In the application that you are building, users add items to their shopping carts and may also
perform other operations on their shopping carts. In this exercise, you add the Java code to add
an item to the cart; you must first generate a Java class for OrderEO where you can add the
code. Because the code uses methods from OrderItemEOImpl.java, you first generate that
Java class without adding any code to it.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Generate the Java class for OrderItemEO.


a. Open OrderItemEO in the editor and click the Java tab.
b. Click Edit .
c. Select the Generate Entity Object Class check box and click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
d. Save your work.
h a s uid
2. Generate the Entity Object Java class) for OrderEO
o m e n t Gfrom
and add the following method for

the \files subdirectory a


lฺc tuddirectory.) the addItemToOrder.txt file in
adding an item to the cart: (You can
ofiyour \labs
copy the code

g mthe entity
i s S
a. Similarly, generate
o @ t h object class for OrderEO.
b. Clickv i n
ฺ the Entity Object Class link to open OrderEOImpl.java in the editor.
( a c
A C
n o d
Vi

c. Note that the Structure window shows the methods that are included in the class. (If
the Structure window is not visible—that is, the default location is at the lower left of the
IDE—then you can select View > Structure to open it.) You can see accessors (getters
and setters) for all the OrderEO attributes. You can double-click any method to

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 4
navigate to it in the editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

d. In the editor, scroll to the bottom of the file and just above the closing right brace, add u se
the code shown below. You can copy the code from the addItemToOrder.txt file in
e to
the \files subdirectory of your \labs directory. n s
i ce
/**
b l el
* Add an item to the order. Typically used to add items to the
fe ra
shopping cart.
a n s
*
n - tr
* @param productId
a no eฺ
*/
h a s uid
m ) nt G
public void addItemToOrder(Number productId) {
l ฺ o
c tude
i
if (productId == null) {

g ma is S
System.err.println("NO PRODUCT ID!!!");
o@ th
throw new NullPointerException();
c ฺ vin
}
( a
A C
d RowIterator orderItems = getOrderItem();
V ino assert orderItems != null;

OrderItemEOImpl row;
boolean found = false;
for (row = (OrderItemEOImpl)orderItems.first(); row != null;
row = (OrderItemEOImpl)orderItems.next()) {
if (row.getProductId().equals(productId)) {
found = true;
break;
}
}

if (found) {
Number qty = row.getQuantity();
if (qty == null)
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 5
qty = new Number(1);
else
qty = qty.add(1);
row.setQuantity(qty);
} else {
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

OrderItemEOImpl newItem =
(OrderItemEOImpl)orderItems.createRow();
EntityDefImpl productEODef =
EntityDefImpl.findDefObject("oracle.fod.storefront.entity.Produc
tEO");

EntityImpl productEO =
productEODef.findByPrimaryKey(getDBTransaction(), new Key(new
u se
Object[] { productId }));
e to
Number unitPrice =
n s
(Number)productEO.getAttribute("ListPrice");
i ce
b l el
newItem.setProductId(new Number(productId));
fe ra
newItem.setQuantity(new Number(1));
a n s
newItem.setUnitPrice(unitPrice); n - tr
try { a no eฺ
h a s uid
getDBTransaction().validate();
m ) nt G
l ฺ o
} catch (TxnValException e) {
c tude
i
ma is S
System.out.println(e.getMessage());
g th
for (Throwable t : e.getExceptions()) {
@
o
vin
System.out.println(t.getMessage());
a c ฺ }
C ( } catch (JboException e) {
d A
i n o System.out.println(e.getMessage());
V }
}
}

e. Press Alt + Enter if prompted to import the following:


oracle.jbo.TxnValException
oracle.jbo.JboException
f. Right-click the editor and select Make from the context menu, and then save your
work.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 6
Practice 7-2: Programmatically Assigning a Database Sequence
You had previously set a declarative type for an EO attribute to use a database sequence. This
technique results in few (if any) gaps in the numbers that are assigned. However, it may be
confusing for users to see a negative number until the record is committed. Another
disadvantage is that there must be a database trigger to assign the actual value.
Another technique for using a database sequence is to programmatically assign the database
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

sequence value as the default value for an attribute. No database trigger is required, but if the
record is never committed, this results in gaps in the numbers. In this practice, you implement
this “eager” assignment of values from a database sequence.
1. Set OrderItemEO to use a database sequence for the line item ID by supplementing the
initDefaults() method with the following code: (You can copy the code from the
initDefaults.txt file in the \files subdirectory of your \labs directory.)
SequenceImpl seq = new SequenceImpl("ORDER_ITEMS_SEQ",
getDBTransaction()); u se
e to
populateAttributeAsChanged(LINEITEMID, seq.getSequenceNumber());
n s
a. Double-click the OrderItemEOImpl.java file in the Application Navigator
l i ctoeopen
the source file—it is located under the OrderItemEO node.
a b le
b. From the context menu, select Source > Override Methods.fe r
c. In the Override Methods dialog box, select the check box a n s
next to the method
initDefaults() : void and click OK (whereas n r
-tin the Override Methods dialog
o
bar). s a n idtoenavigate
box, you can just start entering the method name ฺ to it, or use the scroll

) ha t Gu
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

d. After the line:


super.initDefaults();
Add the code shown above. You can copy the code from the initDefaults.txt file
in the \files subdirectory of your \labs directory.
e. Press Alt + Enter when prompted to import oracle.jbo.server.SequenceImpl.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 7
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. Right-click the method name initDefaults, and then select the Quick JavaDoc option
from the context menu. JDeveloper displays an explanation of the method. Click
outside of the doc window to close it.
g. Right-click the editor and select Make and make sure that no compilation errors are u se
reported in the Compiler Log pane. e to
n s
h. Save your work. i ce
2. Test the assignment of the line item ID. b l el
a. Run the FODShoppingCartAM application module. fe ra
b. Double-click OrderItemsOrdersFkLink1. This opens the master-detail window for a n s
Orders and OrderItems. n - tr
a no eฺ
c. Click Insert a new row s paneuofidthe window (the OrderItems
in the bottom
h a
section).
m ) nt G
d. Note that the row is created
l ฺ o d e
c withtauLineItemId value defaulted from the database
sequence ORDER_SEQ. a i
g m is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

e. Because there are a number of mandatory columns, do not commit the new row.
f. Close the BC Browser without committing the row.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 8
Practice 7-3: Populating History Columns When There Is No Logged-
in User
You previously designated some attributes as history columns in the OrderEO, OrderItemEO,
and SupplierEO entity objects. However, because there was no logged-in user in the Business
Components Tester, you were not able to designate the CreatedBy and LastUpdatedBy
attributes as history columns.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

In this practice, you add code to entity objects to automatically populate the CreatedBy and
LastUpdatedBy history columns.
1. In SupplierEO, modify the CreatedBy and LastUpdatedBy columns as follows:
a. Open the SupplierEO entity object, and click the Attributes tab.
b. For both attributes, delete the anonymous default value.
c. Designate the column as a history column with the appropriate value:
u se
Attribute Name History Column value
e to
n s
CreatedBy created by
i ce
LastUpdatedBy modified by
b l el
fe ra
2. Optional step: (If you choose not to complete this step, you must begin the practices
a n s
n - tr
for the next lesson by opening the starter application.)
no eฺ
Similarly, designate the same columns as history columns in OrderEO and OrderItemEO.
a
3. s uid
As you did previously for OrderEO and OrderItemEO, generate the entity object class for
h a
SupplierEO.
m ) nt G
4.
l ฺ o
c tude
In the entity object class for SupplierEO, override the
i
g ma is S
getHistoryContextForAttribute() method with the following code, which you can
copy from the getHistoryContextForAttribute.txt file in the \files subdirectory
@ th
ฺ v ino
of your \labs directory:
a c
(attributeDefImpl)
protected Object getHistoryContextForAttribute(AttributeDefImpl
A C {

n o d Object value =
V i super.getHistoryContextForAttribute(attributeDefImpl);
// If value is null and is modify user or create user
// history column then return "anonymous"
if (value == null && (attributeDefImpl.getHistoryKind() ==
AttributeDefImpl.HISTORY_MODIFY_USER ||
attributeDefImpl.getHistoryKind() ==
AttributeDefImpl.HISTORY_CREATE_USER))
{
return "anonymous";
}
return value; }
a. Open the Java class in the editor.
b. From either the main menu or the context menu, select Source > Override Methods.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 9
c. In the Override Methods dialog box, select the check box to the left of the
getHistoryContextForAttribute(AttributeDefImpl) : Object method
and click OK. (You can use the filter field.)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
d. Substitute the code shown above for the generated code. You can copy the code from b l el
the getHistoryContextForAttribute.txt file in the \files subdirectory of
fe ra
your \labs directory.
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i 5. Optional step: (If you choose not to complete this step, you must begin the practices
for the next lesson by opening the starter application.)
Similarly, override the getHistoryContextForAttribute() method with the same
code in the entity object classes for OrderEO and OrderItemEO.
6. Run the TestAM application module and perform the same tests as you did in step 4 of
practice 6-3, (Supplier1 and also ShoppingCart1>OrderItemsOrdersFKLink1) except
that if you test the shopping cart, you will not be able to see how the history columns
appear in the shopping cart item record because the history columns are no longer part of
the ShoppingCartItemVO view object.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 10
Practice 7-4: Creating and Running a Test Client
In this practice, you create a Java client to experiment with some of the view object APIs.
1. Create a test client class named StorefrontTest in the
oracle.fod.storefront.test package.
a. In the Application Navigator, right-click the oracle.fod.storefront.test package and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

select New from the context menu.


b. In the New Gallery:
1) Select General in the Categories list.
2) Select Java Class in the Items list.
3) Click OK.
c. In the Create Java Class dialog box:
1) Enter a name of StorefrontTest.
2) Make sure that only the Main Method check box is selected, and then click OK. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
2. a
Use( the bc4jclient shortcut to generate the test client code.
C
A a. StorefrontTest.java opens in the editor. If it does not open, double-click it in the
n o d
V i Application Navigator to open it.
b. Delete the only line of code in the main() method and in its place, enter
bc4jclient, and press Ctrl + Enter to instantiate a BC4J application module.
3. Add code to print the number of rows in the PaymentOption view object, to execute the
query on the PaymentOption view object, and to print CustomerId and
PaymentTypeCode for all rows. Use the TestAM application module.
a. In the stub client code that is generated in the test client, modify the lines:
String amDef = "test.TestModule";
String config = "TestModuleLocal";
Change them to:
String amDef = "oracle.fod.storefront.test.TestAM";
String config = "TestAMLocal";
b. In the test client, change the line:
ViewObject vo = am.findViewObject("TestView");
to:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 11
ViewObject vo = am.findViewObject("PaymentOptionV1");
c. After the line:
// Work with your appmodule and view object here
and above the line:
Configuration.releaseRootApplicationModule(am, true);
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

add the following code: (You can copy it from the TestClient.txt file in the \files
subdirectory of your \labs directory.)
System.out.println("The table contains " +
vo.getEstimatedRowCount() + " rows:");
vo.executeQuery();
while (vo.hasNext()){
Row paymentOptionRow = vo.next();
System.out.println(" CustomerID: " + u se
e to
paymentOptionRow.getAttribute("CustomerId") +
n s
" Payment Type Code: " +
i ce
paymentOptionRow.getAttribute("PaymentTypeCode"));
b l el
}
fe ra
Your code should look like the following: a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 12
4. Right-click the editor and select Run. The test client runs and should display the data in the
log window. It ends when the log displays the message: “Process exited with exit
code 0.”
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 13
Practice 7-5: Creating an Application Module Base Class
The Storefront application currently does not implement security. When the application is
eventually finished, security will be implemented and there will be a login module. However, for
testing and development purposes in the meantime, there must be a way to identify which
customer is using the application, so that shopping cart and checkout information for only that
customer appears in the application.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

In the Java class that you create in this practice, the customer name is hard coded to simulate a
name that would ordinarily be retrieved from a login module.
1. Create a new Java Class named BaseApplicationModuleImpl in the
oracle.fod.storefront.module package, extending the default base application
module.
a. Right-click the oracle.fod.storefront.module package and select New.
b. In the New Gallery:
1) Select General in the Categories list. u se
e to
2) Select Java Class in the Items list.
n s
3) Click OK. i ce
c. In the Create Java Class dialog box: b l el
1) Enter a name of BaseApplicationModuleImpl. fe ra
a n s
2) tr
Ensure that the package name is set to oracle.fod.storefront.module.
n -
3) Next to the Extends field, click Browse. no
a) In the Class Browser dialog box,
a s eฺ tab and enter AMI
aclick theidSearch
(uppercase) in the Match) h Name
Class G ufield, which displays a list of matching
classes. om den t
i l ฺ c u
g ma is St
b) Select the ApplicationModuleImpl(oracle.jbo.server) class and click OK.

o@ th
ฺv i n
C (ac
d A
n o
Vi

4) Click OK to create the class and open it in the editor.


2. Add and initialize a private String variable named mCurrentUser.
a. Place your cursor just after the line:
public class BaseApplicationModuleImpl extends
ApplicationModuleImpl {
b. Press Enter to begin a new line.
c. Add the following declaration:
private String mCurrentUser = null;

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 14
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

3. Override the getUserPrincipalName() : String method and replace the default


return statement with code that sets the current user to a hard-coded user: DRAPHEAL.
a. From the menu, select Source > Override Methods.
b. In the Override Methods dialog box, select the check box next to the
getUserPrincipalName():String method and click OK (whereas in the Override
Methods dialog box, you can just start entering the method name to navigate to it). u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

c. In the method, delete the line:


return super.getUserPrincipalName();
and replace it with the following code: (You can copy it from the
getUserPrincipalName.txt file in the \files subdirectory of your \labs
directory.)
/* TODO: This should be removed as soon
* as we have a working security model
*/
if (mCurrentUser == null) {
String userPrincipal = "DRAPHEAL";
mCurrentUser = userPrincipal;

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 15
}
return mCurrentUser;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
4. Compile and save the code. h a s uid
a. Right-click the editor and selectm )
Make. nt
G
o e
ilฺc displays
b. Ensure that the log window
a S t u dno compilation errors. It should display the
g m compilation:
message: Successful i s 0 errors, 0 warnings.
@ t h
c. Save your
ฺ v inowork. The default preference in the IDE is to automatically save before
compiling.
( ac
d AC
Vi no

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 16
Practice 7-6: Editing an Application Module to Extend the New Base
Class
In this practice, you edit the shopping cart application module so that it extends the base class
that you just created.
1. Edit FODShoppingCartAM and generate a Java class for it that extends
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

BaseApplicationModuleImpl.
a. Open FODShoppingCartAM in the editor.
b. Click the Java tab.
c. Click Edit next to Java Classes.
d. In the Select Java options dialog box:
1) Select the Generate Application Module Class check box.
2) Because you must use the method in the BaseApplicationModuleAMImpl class
that you created earlier, this application module class must extend that one, so u se
click Classes Extend. e to
n s
3) In the Override Base Classes dialog box:
i ce
a) Click Browse next to the Object field.
b l el
b) In the Find Superclass dialog box, click the Search tab and enter BA in the fe ra
n
Match Class or Package Name field. This should populate Matching Classes
a s
and Packages. n - tr
no eฺ
c) Select the BaseApplicationModuleImpl class and click OK.
a
a s uid
d) Click OK again to close the Override Base Classes dialog box.
h
e. m ) nt G
Click OK to generate the application module class.
l ฺ o
c tude
f. Save your work. i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 17
Practice 7-7: Adding and Exposing Service Methods
The shopping cart application module in the completed application contains several methods for
initializing and managing the shopping cart. In this practice, you add two of these methods and
expose them to the client interface.
1. Examine the client interface for the application modules that you have created.
a. Expand the Data Controls panel and expand each of the FOD application modules.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. You can see that the view objects and some operations are exposed to the client. Now u se
you add some service methods and expose them to the client as well. e to
n s
2. Add a method to the shopping cart application module to initialize the shopping cart to that
i ce
of the current user of the application (remember that you hard coded the username in
b l el
BaseApplicationModuleImpl.java). The code is shown here: (You can copy the code
fe ra
from the ShoppingCartInit.txt file in the \files subdirectory of your \labs
a n s
directory.)
n - tr
public void init() {
a no eฺ
a s uid
DBTransactionImpl trx = (DBTransactionImpl)getDBTransaction();
h
ApplicationModuleImpl am =
m ) nt G
ฺ o
c tude
(ApplicationModuleImpl)trx.getRootApplicationModule();
l
i
ma is S
String user = am.getUserPrincipalName().toUpperCase();
g
@ th
System.out.println("The session user is: " + user);
o
c ฺ vin
ViewObjectImpl vo;
( a vo = getShoppingCart1();
A C String bindUser =
n o d (String)vo.getNamedWhereClauseParam("CurrentUser");
V i if (! user.equals(bindUser)) {
vo.setNamedWhereClauseParam("CurrentUser", user);
/* The ShoppingCart is guaranteed to only have one row.
* However, we may not always properly initialize this
* from the UI because the actual row from ShoppingCart is
* not really needed. The following initializes the view
* object so that the view link to the shopping cart items
* properly works.
*/
vo.executeQuery();
Row cart = vo.first();
if (cart == null) {
cart = vo.createRow();
// TODO: Need to finish this off.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 18
cart.setAttribute("OrderDate",
((DBTransactionImpl)getDBTransaction()).getCurrentDbTime());
cart.setAttribute("OrderStatusCode", "CART");
vo.insertRow(cart);
}
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

}
}
a. In the Application Navigator, expand FODShoppingCartAM and double-click
FODShoppingCartAMImpl.java to open it in the editor.
b. Add the code shown above just before the closing right brace.
c. Press Alt + Enter if prompted to import the following:
oracle.jbo.Row
oracle.jbo.server.DBTransactionImpl u se
oracle.jbo.server.ApplicationModuleImpl
e to
3. Now add a method that adds an item to the user’s shopping cart. This method should call n s
i ce
an entity object method that you added earlier to OrderEOImpl.java. Use the following
b l el
code (you can copy from addItemToCart.txt):
fe ra
public void addItemToCart(Number productId) {
a n s
init();
n - tr
no eฺ
ViewObject shoppingCartVO = getShoppingCart1();
a
assert shoppingCartVO != null;
h a s uid
m ) nt G
l ฺ o
c tude =
i
ViewRowImpl shoppingCartRow
ma is S
(ViewRowImpl)shoppingCartVO.first();
g
assert@ th
o shoppingCartRow != null;
ฺv i n
C (ac OrderEOImpl orderEO =
d A (OrderEOImpl)shoppingCartRow.getEntity(0);
n o
Vi
orderEO.addItemToOrder(productId);
}
a. Insert the code just before the closing brace in FODShoppingCartAMImpl.java.
b. Press Alt + Enter if prompted, to import the following:
oracle.jbo.ViewObject
oracle.jbo.server.ViewRowImpl
oracle.fod.storefront.entity.OrderEOImpl.
c. The code shows an error when calling the addItemToOrder() method. To fix it,
manually add the following import statement to the import section of the file:
import oracle.jbo.domain.Number;
d. Right-click the editor and select Make.
e. Save your work.
4. Now that you have written the service methods to initialize and add items to the shopping
cart, expose the new methods to the client interface.
a. Examine the Data Controls panel again. It looks the same as before. The new methods
are not yet available to the client interface.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 19
b. Edit FODShoppingCartAM and click the Java tab.
c. In the Client Interface section of the Java panel, click Edit .
d. In the Edit Client Interface dialog box, shuttle the init() and addItemToCart()
methods to the Selected list, and then click OK.
e. Save your work.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. In the Application Navigator, expand FODShoppingCartAM and observe that two


additional Java files have been generated:
1) An FODShoppingCartAM interface
2) An FODShoppingCartAMClient class that implements the interface
g. Examine the Data Controls panel again. Click the Refresh button. You can now see the
service methods that you added. These methods are now available for use in a client,
such as the Storefront UI that you build later in this course.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 20
Practice 7-8: Restrict the Shopping Cart Query
Now that you have added a method to initialize the shopping cart, in this practice, you modify
the shopping cart to display only the cart for the current user.
1. Edit the shopping cart view object to restrict the shopping cart to display only the status
CART order belonging to one user. Use a bind variable named CurrentUser.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Hint: This should be a String that is contained in the Principal_Name column of


PersonEO.
a. In the oracle.fod.storefront.uiview package, open ShoppingCartVO in the editor.
b. Click the Query tab.
c. Click Edit.
d. In the Query dialog box:
1) The WHERE clause already reads:
OrderEO.CUSTOMER_ID = PersonEO.PERSON_ID u se
Append to the WHERE clause: e to
n s
i ce
el
AND OrderEO.ORDER_STATUS_CODE = 'CART'
AND PersonEO.PRINCIPAL_NAME = :CurrentUser
a b l
fe r
a n s
n - tr
a no eฺ
h a s uid
m) inethen G
t tree
2) Select Query > Bindฺc
l o
Variables d at the left.
i t u
g ma panel,
3) In the Bind Variables
i s S click New.
4) Enter a@ th of CurrentUser and click OK.
o variable name
ฺv i n
C (ac
d A
n o
Vi

2. Test the shopping cart. Execute the init() method, but do not supply a value for the bind
variable, because that comes from the init() method.
a. Run FODShoppingCartAM.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 21
b. When the Business Components Browser appears, right-click the
FODShoppingCartAM node and select Show, or simply double-click the node.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Select init from the Method drop-down list.


d. Click Execute. The Result should be success.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
e. i
Double-click ShoppingCart1.
f. g madialogisbox,
In the Bind Variables
S click Cancel, because the init() method already
assigned o@
the t h
value to the bind variable.
ฺ v i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 22
g. One record should be returned by the query: the status CART order for DRAPHEAL.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
a i S
h.
g mwindow.
Close the Browser
i s
o@ t h
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 23
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 7


Chapter 7 - Page 24
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 8
n - r
Chaptern8o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 2
Practices for Lesson 8: Validating User Input
Practices Overview
In this practice, you add several types of both declarative and programmatic validation to entity
objects.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

If you have successfully completed all sections of the previous practice, including the optional
steps, you can continue working in the same project. However, if you prefer to start with a clean
application that contains everything completed up to the start of this lesson, open
Storefront-08.jws and edit the database information as described in step 4 of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 3
Practice 8-1: Adding Declarative Validation: List Validator
In this practice, you define a List validator for the status code of an order.
1. Add validation to the OrderStatusCode attribute of the OrderEO entity object to ensure
that the value entered is valid. Display a meaningful error message to the user when
validation fails, using the resource bundle.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Hint: Use the LOOKUP_CODES table.


a. In the Application Navigator, in the oracle.fod.storefront.entity package, right-click
the OrderEO entity object and select Open OrderEO from the context menu.
b. In the Entity Object Editor, select the Attributes node, and then select the
OrderStatusCode attribute.
c. You can invoke the Add Validation Rule dialog box either from the Attribute Editor, or
with the attribute selected, from the Validation Rules accordion of the Entity Object
Editor. Invoke the Add Validation Rule dialog box in one of the following ways:
u se
1) With the OrderStatusCode attribute selected, click Edit. Then in the Attribute
e to
Editor, select Validation in the tree at the left, and then click New.
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
a i S the OrderStatusCode attribute in the Entity Object
g
2) Alternatively, m i s
after selecting
t h
oin@the Validation Rules accordion of the editor, click Add Validation Rule.
Editor,
ฺv i n
C (ac
d A
n o
Vi
d. In the Add Validation Rule dialog box:
1) Select List in the Rule Type drop-down list.
2) Leave the Operator at its default value of In.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 4
3) Select Query Result from the List Type drop-down list.
Note: This is not the recommended way to define list validation. It is preferable to
use a view accessor attribute for this type of lookup.
4) In the Enter SQL statement field, enter the following query:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

select distinct lookup_code from lookup_codes


where lookup_type = 'ORDER_STATUS_CODE'
5) Click Test to test the query. A message should inform you that the query is valid.
Click OK to close the validation message.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

e. On the Failure Handling tab, check whether the Validation Failure Severity option
button is set to Error, and then, to define a translatable string in a resource bundle,
click in the Message Text section. If you do not choose to do so, in the interest of
time, you can simply enter the text rather than clicking to define a text resource. If
you choose this option, enter ”You have entered an invalid value” in the
Message Text field and skip step (f) below.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. If you choose to define a text resource, simply click this option . In the Select Text
Resource dialog box:
u se
1) In the Display Value field, enter: You have entered an invalid value
e to
2) In the Key field, enter: INVALID_VALUE n s
i ce
3) In the Description field, enter: Error message for invalid value
b l el
4) Click Save and Select.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

g. Click OK to save your validation definition, and then click OK to close the Attribute
Editor if you used it to invoke the Add Validation Rule dialog box.
2. Save your work. You will test this validation after all validations are defined.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 6
Practice 8 -2: Adding Declarative Validation: Unique Key Validator
In this practice, you add validation to the OrderEO entity to ensure that a duplicate value is not
entered for the primary key.
1. Add a Unique Key validator for OrderEO. Display a meaningful error message to the user
when validation fails.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Entity Object Editor for the OrderEO entity, select the Business Rules node.
b. In the Business Rules section, select Entity Validators, and then click Create new
validator to add a new rule. (Note that this is another way to define attribute
validation if you expand the Attributes node and select an attribute.)

u se
e to
n s
i ce
b l el
fe ra
c. In the Add Validation Rule dialog box:
a n s
- tr
1) Select UniqueKey from the Rule Type drop-down list.
n
2) Select OrdersPk(ORDER_ID) in thea nolist.eฺ
Keys
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

3) On the Failure Handling tab:


a) Check whether the Validation Failure Severity option is set to Error.
b) As you did previously, using the icon, you can add, save, and use the
message You have entered a duplicate ID, using a Key of
DUPLICATE_ID and a Description of Error message for unique key
validation (alternatively, simply enter the hard-coded Message Text).

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 7
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
4) fe
Click OK to save your validation definition. You should see the new validation rule ra
in the Validation Rules section of the OrderEO editor. a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d2. Save your work. You will test this validation after all validations are defined.
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 8
Practice 8-3: Adding Programmatic Validation: Method Validator
In this practice, you add a programmatic validation method for the OrderShippedDate
attribute of the OrderEO entity.
1. Add a Method validator to verify that the shipping date of an order is not prior to the order
date, and display a meaningful error message when validation fails. You can use the
following code: (You can copy the code from the ShippedDateAfterOrderDate.txt
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

file in the \files subdirectory of your \labs directory.)


public boolean validateShippedDateAfterOrderDate(Date
ordershippeddate) {
return ordershippeddate == null ||
ordershippeddate.dateValue().compareTo
(getOrderDate().dateValue()) >= 0;
}
u se
a. In the editor for the OrderEO entity, select the Attributes node, and then select the e to
OrderShippedDate attribute. n s
i ce
b. Invoke the Add Validation Rule dialog box as you did previously for the
b l el
OrderStatusCode attribute.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

c. In the Add Validation Rule dialog box:


1) Select Method in the Rule Type drop-down list.
2) Ensure that the Create and Select Method check box is selected.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 9
3) For Method Name, enter the value validateShippedDateAfterOrderDate
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
d. On the Failure Handling tab:
fe ra
n s
1) Check whether the Validation Failure Severity option button is set to Informational
a
Warning. n - tr
no eฺ
2) As before, add, save, and use the message Order shipped date must not
a
a s uid
be prior to order date, using a Key of SHIP_DATE_TOO_SOON and a
h
) nt G
Description of Warning message for validation of shipping date.
m
ฺ o
c tude
Click Save and Select. Alternatively, you can just enter the message in the
l
i
ma is S
Message Text field.
g
o@ th
c ฺ vin
( a
A C
n o d
V i

e. Click OK to save your validation definition. (Click OK again to dismiss the Attribute
Editor if you used it to invoke the Add Validation Rule dialog box.)
f. In the Application Navigator, expand the OrderEO node and double-click
OrderEOImpl.java to open it in the editor (by adding the Method validator, this file
would have been automatically generated if it did not already exist).
g. In the Structure window, double-click the validateShippedDateAfterOrderDate
method to locate it in the editor.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

h. Replace the method with the code specified in step 1.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
i.
j.
Right-click and select Make.
a no eฺ
Save your work. You will test this validation after all validations are defined.
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 11
Practice 8-4: Creating and Using a Domain for Validation
In this practice, you create a domain for a short email address data type. You then apply that
domain as the data type for a customer’s email address.
1. Create a domain named PhoneNumber. It should be a string 12 characters in length with
the format xxx.xxx.xxxx.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, right-click the oracle.fod.storefront node and select New
Domain.
b. On the Name page of the Create Domain Wizard:
1) Set the package name to oracle.fod.storefront.domain.
2) Set the Name to PhoneNumber.
3) Ensure that the Domain for an Oracle Object Type check box is not selected.
4) Click Next.
c. On the Settings page of the wizard: u se
1) Select String from the Type drop-down list. e to
n s
2) Click Next, and then click Finish. i ce
d. In the Application Navigator, double-click PhoneNumber.java to open it in the editor. It b l el
is located under the oracle.fod.storefront > domain > PhoneNumber node.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
e. In the Structure window, double-click the validate():void node to navigate to that

n o d method in the code.


V i f. After the commented line in the validate() method, add the following custom
domain validation logic: (You can copy the code from the PhoneNumber.txt file in
the \files subdirectory of your \labs directory.)
int dot1pos = mData.indexOf('.');
int dot2pos = mData.lastIndexOf('.');
int ln = mData.length();
if (dot1pos != 3 || dot2pos != 7 || ln != 12) {
throw new DataCreationException(null,
"Invalid phone number - format is xxx.xxx.xxxx",null);
}

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 12
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Press Alt + Enter when prompted to accept the import of


oracle.jbo.domain.DataCreationException.
g. Right-click and select Make.
h. Save your work.
2. Apply the domain to the PhoneNumber attribute of SupplierEO. u se
a. Open SupplierEO in the editor. e to
n s
b. Click the Attributes tab.
i ce
c. Select the PhoneNumber attribute and click Edit (or simply double-click the attribute).
b l el
d. In the Edit Attribute dialog box:
fe ra
1) Select Entity Attribute in the list at the left.
a n s
2) From the Type drop-down list, select n - tr
no eฺ
oracle.fod.storefront.domain.common.PhoneNumber.
a
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

3) Click OK.
3. Save your work.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 13
Practice 8-5: Testing the Validation
In this practice, you test all the validation that you have defined.
1. Run FODShoppingCartAM and test the List validator that you defined for the OrderEO
entity object. Be sure to initialize the cart first to bring up the status CART record for
DRAPHEAL.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, right-click FODShoppingCartAM and select Run.


b. If necessary, click Connect to establish the connection.
c. When the Business Components Browser appears, double-click the
FODShoppingCartAM node, select init from the Method drop-down list, and click
Execute to execute the init method.
d. Double-click ShoppingCart1 and in the Bind Variables dialog box, click Cancel to
leave the bind variable at the value that was set by the init() method.
e. Change the OrderStatusCode to XXXX and tab out of the field. You should receive the
u se
error message that you defined.
e to
Note: If you defined the validation error message by entering hard-coded text, the error n s
message text looks the same, but the JBO error is a rather cryptic generated key i ce
instead of INVALID_VALUE. b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i
f. Click OK to acknowledge the error.
g. Change the OrderStatusCode back to its original value (CART) so that you can
navigate out of the field.
2. While still in FODShoppingCartAM, test the Unique Key validator that you defined for the
OrderEO entity object.
a. Make note of the current value of the OrderId field.
b. Change the OrderId to a value that already exists, such as 1001, 1002, or 1003.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 14
c. Tab out of the field. You should receive the error message that you defined.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
d. Click OK to acknowledge the error. e to
n s
e. Change the OrderId back to its original value so that you can navigate out of the field.
i ce
3. While still in FODShoppingCartAM, test the Method validator that you defined for the
b l el
OrderEO entity object.
fe ra
a. Enter a value in Order Shipped Date that is later than the value in Order Date. You
a n s
should be able to tab out of the field with no error.n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
b. main Order
Enter the same value
g is SShipped Date that is in Order Date. You should be able
to tab out of@ t
the field withh no error.
ฺ v ino
C (ac
d A
n o
Vi c. Enter a value in Order Shipped Date that is earlier than the value in Order Date. You
should receive the warning message that you defined. (The JBO key is different if you
entered hard-coded message text rather than defining a text resource.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 15
d. Click OK to acknowledge the message. You should notice that navigation to the next
field was successful, because you defined failure handling to be an informational
warning rather than an error.
e. Close the Business Components Browser.
4. Run TestAM to test the domain that you defined and applied to the SupplierEO entity
object.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, right-click TestAM and select Run.


b. If necessary, click Connect to establish the connection.
c. When the Business Components Browser appears, double-click the Supplier1 node.
d. Navigate to a supplier with a phone number. Change the phone number in various
ways, such as by deleting the dots (.) or by making the phone number longer. Each
time that the phone number does not conform to the format xxx.xxx.xxxx, you
should not be able to tab out of the field. Doing so should result in receiving the error
message that you defined. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o d e
c tuBrowser
i
e.
g ma is S
Close the Business Components when you have finished.

o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 8


Chapter 8 - Page 16
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 9
n - r
Chaptern9o
s a ideฺ
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 2
Practices for Lesson 9: Troubleshooting ADF BC Applications
Practices Overview
Most of the techniques for troubleshooting are used mainly for debugging a user interface.
However, you can run the JDeveloper Debugger with the Business Components Browser, which
enables you to troubleshoot problems with your ADF BC model apart from running a Fusion
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Web application. In the practices for this lesson, you debug a client method in an application
module, and you explore the features of the JDeveloper Debugger.
Note: This practice is optional, and does not affect subsequent practices. Do this practice only if
you have extra time.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 3
Practice 9-1: Discovering Application Problems
In this practice, you test the Storefront application and discover a problem at run time.
1. Open the StorefrontDebug application from the StorefrontDebug folder. As you have
been doing, run the FODShoppingCartAM application module and initialize the shopping
cart, and then display the shopping cart.
a. From the JDeveloper application menu, select Open Application.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Navigate to the StorefrontDebug folder and open the StorefrontDebug application. u se


This application is identical to the one you have been working on, except that an error
e to
has been introduced. n s
i ce
c. If prompted to migrate the application, perform the migration steps.
b l el
d. Modify the connection to point to your schema and edit the database information as
fe ra
described in step 4 of Practice 2-4. s
e. tr
In the oracle.fod.storefront.module package, run FODShoppingCartAM. a n
n -
f. Initialize the shopping cart:
a no eฺ
h a s uid
1) In the Business Components Browser, double-click FODShoppingCartAM.
) nt G
2) Select init from the Method drop-down list.
m
ฺ o
c tude
3) Click Execute to execute the init method.
l
i
g. ma is S
Display the shopping cart:
g
@ th
1) Double-click ShoppingCart1.
o
ฺ vin
2) In the Bind Variables dialog box, click Cancel so that the value that was set by
c
( a the init() method is used.
A C 3) The cart does not display a user’s order, as expected, but instead displays a blank
n o d (except for default values) new record.
V i
h. Close the Business Components Browser.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 4
Practice 9-2: Setting Breakpoints in the Debugger
You know that there is a record in the shopping cart, but it did not appear in the Business
Components Browser. Now that you have discovered a run-time problem, in this practice, you
prepare to use the JDeveloper Debugger.
1. You know that the init() method of the FODShoppingCartAM application module sets
up the shopping cart. Set a source breakpoint in that method.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, select FODShoppingCartAMImpl.java.


b. In the Structure window, right-click init():void and select Go to Source.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
@ th
ฺ v ino
c. Tocset a breakpoint, click in the left margin of the code editor next to the first line of
a
(executable code in the init() method.
A C
n o d
V i

2. You know that the value of the mCurrentUser variable in


BaseApplicationModuleImpl.java receives the value of the current user of the application.
Set a watchpoint breakpoint for when this value changes.
a. In the Application Navigator, in the oracle.fod.storefront.module package, select
BaseApplicationModuleImpl.java.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 5
b. In the Structure window, click the Show Fields button, and then right-click
mCurrentUser:String and select Create Watchpoint.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
3. View all the breakpoints that are set on the s id
application.
h a u
a. From the JDeveloper main menu,) select View
o m e n t G> Breakpoints (or use the shortcut key
ilฺc Stud
combination Ctrl + Shift +R).
a
g m is
o@ th
v i n
( acฺ
d AC
Vi no b. The Breakpoints window shows the breakpoints that you have set, in addition to those
persistent breakpoints that are set by default.

c. Right-click the Breakpoints window to see the options that are available in the context
menu (but do not make any changes).

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 6
Practice 9-3: Running the Application Module in Debug Mode
Now that you have some breakpoints, in this practice, you run the application in debug mode
and use some of the features of the JDeveloper Debugger.
1. Run FODShoppingCartAM in debug mode.
a. In the Application Navigator, right-click FODShoppingCartAM and select Debug.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
li ce
l e
binvoked in the
b. Before the Business Components Browser appears, the debugger
e r ais
JDeveloper IDE. Examine the information in the IDE.
a n sf
1) BaseApplicationModuleImpl.java is shown in-the
n tr editor with a watchpoint icon
is because the application has hit the a nosetting
and a pointer displayed to the left of the line
watchpoint e ฺ
mCurrentUser to null. This
breakpoint that you set on this
a s u i d
variable.
m ) h nt G
i l ฺ co tude
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi 2) If the Stack window is not visible, from the JDeveloper main menu, select View >
Debugger > Stack. You can see in the Stack window that the
BaseApplicationModuleImpl class is in the process of being initialized, and
that it was called by the initialization of FODShoppingCartAMImpl.

c. Step through the code and use the debugger features to figure out the problem.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 7
1) Click Step Into on the JDeveloper toolbar. You can see the pointer move to the
next executable line of code in the editor window.
2) In the Data, expand the this node. Note that the value of mCurrentUser is null.
Also, mCurrentUser appears as its own in the SmartData. You want to keep
track of the value of this variable, so right-click it in the Smart Data or in the Data
panel and select Watch. This adds the variable to a watch list where you can keep
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

track of various values all in one place.

3) Click Resume on the toolbar to continue the execution until the next time a u se
breakpoint is encountered. No breakpoint is encountered, so the Business
e to
Components Browser appears. n s
i ce
4) Now set up the shopping cart as you have done before by executing the init()
method—double-click FODShoppingCartAM in the browser, select the init() b l el
method from the Method drop-down list, and then click Execute. The control fe ra
passes to the debugger again, so click back within the JDeveloper window to
a n s
continue the actions. n - tr
5) a no eฺ
FODShoppingCartImpl.java is shown in the editor with a source breakpoint icon
a s uid
and a pointer displayed to the left of the line in the init() method where you set
h
the breakpoint.
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
c ฺ vin
( a
A C
n o d
V i
6) If you step into the code at this point, you would need to have the ADF source
because ADF source classes are called in the next lines. Because you do not have
the source, click Step Over to advance to the next line of code in this class—
everything still executes, but you just do not step into the called classes. Note: Be
sure to click Step Over and not Step To End of Method, whose icon looks similar.
7) Click Step Over again to advance to the line of code that assigns a value to the
user variable. This assignment calls the getUserPrincipalName() method of
the application module base class, which is overridden in
BaseApplicationModuleImpl.java.
8) You are interested in two variable values: user and mCurrentUser. Click the
Smart Data tab. (If it is not available, use the View > Debugger menu to invoke
it.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 8
9) On the Smart Data tab, collapse all nodes, and then right-click user and select
Watch.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
The Watches tab now shows both the this.mCurrentUser and user variables
so that you can easily track their values. b l el
f e r a
10) Click Step Into to step into the getUserPrincipalName()n s
awhen method in
BaseApplicationModuleImpl.java. Note-that t r you do so, on the
Watches tab the user variable has question n onmarksฺ for value and type because it
is out of scope. s a ide
) a
hThe pointer
G u
11) Click Step Into again twice.
o t
m en should now be on the line that assigns
l
a value to mCurrentUser,
i ฺ c but
t u dthat line of code has not yet been executed. You
a
m valueisof the
can see that the S variable userPrincipal is about to be assigned to
g t h
i n othe@Smart Data tab and notice that the value of userPrincipal is
mCurrentUser.
v
12) ฺClick

C (ac "DRAPHAEL"—this username is misspelled.


d A 13) In the Smart Data panel, right-click the userPrincipal variable and select
n o Modify Value.
Vi

14) In the Modify Value dialog box, change the value to DRAPHEAL, which is the
correct spelling for the username of the user whose shopping cart you want to
display, and then click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 9
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

15) Click Step Into (you


may have to click it twice). On the
Watches tab, you should see that
mCurrentUser now has the value u se
DRAPHEAL, the correct spelling.
e to
n s
e return
16) Click Step Out to execute the remaining lines of code in this method i cand
l
to the FODShoppingCartAMImpl class.
r a ble
17) Click the Watches tab, and then click Step Into and then
n s fe Step Over . You
should see the value DRAPHEAL being assigned to
n - trauser.
18) Click Step Over
named WHERE clause parameter. This a no setiseฺatthethebindlinevariable
four times until the pointer
should
of code that sets the
of the view
a s
hcart order
object’s query to return only )the u i d
m n t G belonging to the user DRAPHEAL.
ฺ o andtuexpand
19) Click the Smart Datactab
mWhereParamsa onilyour watch
dlist.e vo.mViewRowSet, and then place
g m is S
20) Click o @
Step Over thtwice, so that the VO query executes, and then in the Watch
i n
v expand mWhereParams and [0]. You should see that the Current User
ฺpanel,
( a c parameter has been set to DRAPHEAL.
A C
n o d
Vi

21) Click Resume , and then in the Business Components Browser, double-click
ShoppingCart1. Click Cancel in the Bind Variables dialog box so that the value
set by the init method is used. You should see that the correct record appears
now.

You have seen some features of the debugger and how being able to view variable and
parameter values as the code runs can help you to figure out a coding problem. This
code was so simple that you probably could have easily figured it out just by looking at it,
but the debugger can be very useful for troubleshooting complex code. You were able to
change a value while code execution was paused, so that you could see the outcome.
Of course, you would also have to fix the code itself instead of just changing a variable
value in the debugger, but that is not part of this exercise.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 9


Chapter 9 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 10
- r
on ฺ
Chaptern10
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 10


Chapter 10 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 10


Chapter 10 - Page 2
Practices for Lesson 10: Understanding UI Technologies
There is no practice for this lesson.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 10


Chapter 10 - Page 3
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 10


Chapter 10 - Page 4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 11
- r
on ฺ
Chaptern11
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 2
Practices for Lesson 11: Binding UI Components to Data
Practices Overview
In this set of practices, you create a databound JSF page. You then examine the data bindings
and manipulate the data binding files.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Even if you successfully completed all sections of previous practices, do not continue working
in the same project, because there was no time to create all the elements required for the UI.
You must open Storefront-11.jws and then edit the database information as described in
step 4 of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 3
Practice 11-1: Creating Databound Pages
In this practice, you create a product catalog page. It initially contains tables that display product
categories and subcategories for the products that the company sells. Note that a new project
StoreFrontUI now exists for the view part of the application.
1. Create a JSF page named Products.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. With your StorefrontUI project selected in the Application Navigator, select File > New
to invoke the New Gallery. (Alternatively, you can right-click StorefrontUI and select
New from the context menu, or click New on the toolbar.)
b. In the Categories list, select Web Tier > JSF. Select JSF Page in the Items list and
click OK.
c. In the Create JSF Page dialog box:
1) Enter a file name of Products.
2) To the default Directory path, add \oracle\storefront\ui\pages. u se
3) Ensure that Create as XML Document (*.jspx) is selected, and then click OK. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

2. After the designer initializes, the new blank page opens in the editor. Add to the page two
databound tables for product categories and subcategories as master-detail tables.
a. In the Data Controls panel, expand FODProductAMDataControl >
BrowseCategory1.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 4
b. Drag BrowseSubCategory1 to the page, selecting Master-Details > ADF Master
Table, Detail Table from the Create menu.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
3. By default, all attributes of the view objects were added to the tables. You want to display
fe ra
n
only the category name and description. Delete the ones that you do not want to display,
a s
and set the master table to enable row selection.
n - tr
no eฺ
a. To edit the master table, select the top table (BrowseCategory) in either the visual
a
h a s uid
editor or the Structure window and click Edit in the Property Inspector. (If the Property
Inspector is not visible, use the View menu to display it.)
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

b. Delete the columns that you do not want to display by selecting them and clicking
Delete , and you can use the arrows at the right of the Edit Table Columns dialog
box to reorder the columns. Set the column list to match the following:
CategoryName
CategoryDescription
Hint: When you select an attribute, it is best to select the first column, Display Label,
because that is the only column that does not invoke a pop-up list.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 5
Note: Although this short list of attributes is easy to reorder, a quick way to reorder
attributes is to select the one that you want last in the list (in this case,
CategoryDescription), and then click the up arrow to move it to the top of the list.
Then working from the bottom up, repeat for each desired attribute (in this case,
CategoryName). Finally, select all the attributes below the desired attributes and delete
them.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Make sure that Row Selection is selected in the Enable ADF Behavior section at the
top of the window, and then click OK to apply the changes.

u se
e to
n s
i ce
b l el
fe ra
d. Select the second table (BrowseSubCategory1) in either the visual editor or the
a n s
n - tr
Structure window and click Edit in the Property Inspector.
e. no eฺ
Set the column list to match the following (remove the extra columns and reorder as
needed): a
h a s uid
CategoryName
m ) nt G
CategoryDescription
l ฺ o
c check d e and click OK. The page should now look
i t u
mascreenshot,
f. Deselect the Row Selection box
g
similar to the following i s S in which some of the extra white space has been
cut out: o@ t h
c ฺ vin
C (a
d A
n o
Vi

4. Test the page.


a. If the Products.jspx page is not open, click its tab, or reopen it in the editor.
b. Right-click the page editor and select Run. The log window should display messages
relating to starting the server, and then the browser should display your page. This may
take a few minutes, but will be faster the next time that you run a page, because the
server is already started.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 6
c. Select one of the Categories and note that the SubCategories change to reflect the
selected row. Select another category and note the change. You may have to scroll
down to see the SubCategories.
The page should look similar to the following screenshot, in which some of the extra
white space has been cut out:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
e n s
Note that the table does not fill the page. In the practice for the lesson titledc“Achieving
l i
d. Leave the browser window open to refer to in the next task. r ble
the Required Layout,” you modify the layout so that the table fills the page.
a
n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 7
Practice 11-2: Examining the Page’s Data Bindings
In this practice, you examine the data bindings that JDeveloper automatically created on the
page when you dragged a data control to the page.
1. Note the difference in the way the table columns appear in the JDeveloper editor and the
way they appear at run time.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
For example, select the first column in the upper table in the JDeveloper editor, and then

n - tr
look at the Property Inspector. What is the Header Text property set to?
no eฺ
__________________________________________________________________
a
h a s uid
__________________________________________________________________
) nt G
Answer: #{bindings.BrowseCategory1.hints.CategoryName.label}
m
2. ฺ o
c tude
Select the CategoryName output text under the column header. What is its value?
l
i
ma is S
__________________________________________________________________
g
@ th
__________________________________________________________________
o
ฺ vin
Answer: #{row.CategoryName}
c
3.
a
The( reference to row is to a variable that is defined on the table.
A C
n o d Select the table in the Structure window, and then click the Source tab in the editor. How
V i is the row variable defined?
__________________________________________________________________
__________________________________________________________________
Answer:
var="row" value="#{bindings.BrowseCategory1.collectionModel}"
4. At run time, what appears in the browser for the first column’s heading?
__________________________________________________________________
__________________________________________________________________
Answer: The column heading is Category Name.
5. In JDeveloper, in the StorefrontModel project, open the ProductCategoryEO entity object
and edit the CategoryName attribute. Where does the Category Name label in the UI
come from?
__________________________________________________________________
__________________________________________________________________

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 8
Answer: Category Name comes from the entity object attribute’s control hints for
Label.
6. At run time, what appears in the browser for the first column’s values? Where do these
values come from?
__________________________________________________________________
__________________________________________________________________
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Answer: Office, Electronics, and Media are the category names in the rowset;
they are the input values for the category names in the rows.
7. In the Application Navigator, right-click the page and select Go to Page Definition. What is
the name of the page definition file? (You can also view data bindings by clicking the
Bindings tab of the page itself.)
__________________________________________________________________
Answer: ProductsPageDef.xml
u se
8. In the Model section of the page definition file, trace the source of the BrowseCategory1
binding. Where does the data come from? e to
n s
__________________________________________________________________ i ce
__________________________________________________________________ b l el
Answer: The data comes from the BrowseCategory1 view object instance in the fe ra
FODProductAMDataControl. The data is held in the entity object on which the a n s
n - tr
BrowseCategory view object is based, and the values ultimately come from the
database.
a no eฺ
9. a s uid
At the top of the page, click the link to the Data Binding Registry. What is the name of this
h
file?
m ) nt G
l ฺ o
c tude
__________________________________________________________________
i
ma is S
__________________________________________________________________
g
o @ th
Answer: DataBindings.cpx
10. ฺ vin
When does this data binding registry file get created? Hint: The answer is right at the top of
c
( a
the Overview page for the data binding registry file.
A C __________________________________________________________________
n o d
V i __________________________________________________________________
Answer: The file is created the first time that you bind a UI component to data in the
application.
11. What does the Page Mappings section of this file show?
__________________________________________________________________
__________________________________________________________________
Answer: It shows the mapping of pages to the IDs of their associated page definition
files.
12. What does the Page Definition Usages of this file show?
__________________________________________________________________
__________________________________________________________________
Answer: It shows the mapping of page definition file IDs to paths of their page definition
files.
13. What does the Data Control Usages section of this file show?
__________________________________________________________________

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 9
__________________________________________________________________
Answer: It shows the data controls that are used in the application.
14. Close the browser and the files that you have open in the JDeveloper editor. As you add
pages to the application, you can reexamine the data-binding registry to see how page
mappings, page definition usages, and data control usages are shown for the additional
pages.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 10
Practice 11-3: Adding an Additional Detail Table
In this practice, you add the Products table to the page as a detail of the
BrowseSubCategory table.
1. Add data controls to the Products.jspx page.
a. If the Products.jspx page is still open, click its tab, or reopen it in the editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the Data Controls panel, expand FODProductAMDataControl > BrowseCategory1


> BrowseSubCategory1.
c. Drag the BrowseSubCategory1 > BrowseProduct1 data control to the af:form
node in the Structure window.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
a
d. (From the Create menu, select Table > ADF Read-only Table.
C
A e. Do not enable Row Selection.
n o d
V i f. Include the following attributes in order, deleting the other attributes, and then click OK:
ProductName
Description
ListPrice

2. Run the page to test it. Now, when you run the page, the log window shows that the
application is undeployed and then redeployed to the default server.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 11
a. You should note that although the top two tables are coordinated with one another, the
products that appear in the bottom table are those of the first category/subcategory,
and the display of products does not change when different categories or
subcategories are selected. In the practice for the lesson titled “Achieving the Required
Layout,” you use partial page rendering to refresh the Products table so that it
coordinates with the record that is selected in the Subcategory table.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Close the browser when you have finished and undeploy the application as described
in step 6(i) of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 12
Practice 11-4: Renaming a Page
Although there is no facility for refactoring a page name in JDeveloper, you may sometimes
need to rename a page. In this task, you learn how renaming a page affects data binding and
what you must do to reestablish data binding on a renamed page.
1. Rename the Products page ProductCatalog.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Shut down JDeveloper, saving any unsaved work and terminating any running
processes if prompted.
b. Open Windows Explorer and navigate to your application directory.
c. In the StorefrontUI\public-html\oracle\storefront\ui\pages directory,
change the name of Products.jspx to ProductCatalog.jspx.
2. Test the ProductCatalog page.
a. Reopen JDeveloper, and then open the ProductCatalog.jspx page in the editor.
b. Run ProductCatalog.jspx. u se
c. The browser displays error messages, but does not display any data. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
d. When you haveg ma close
finished, i s Sthe browser and undeploy the application as described
t h
@Practice 2-4.
in step 6(i)oof
i n
ฺv Denied” error that you received is indicative of a problem with data bindings.
( a c
3. The “Access
Fix the problem without re-creating the tables on the page.
A C
a. Click the Bindings tab in the editor of the ProductCatalog page to see that there are
n o d
Vi b.
no data bindings for the page.
In the Application Navigator, navigate to StorefrontUI > Application Sources >
oracle.storefront.ui and open DataBindings.cpx.
c. Map the existing page definition file to the renamed page: In the Page Mappings
section of DataBindings.cpx, edit the path. Change Products in the path to
ProductCatalog. You can do this by selecting the page mapping, and then editing
the path in the Property Inspector.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 13
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
4.
d. Save your work.
Test the ProductCatalog page again. b l el
fe ra
a. Close and reopen ProductCatalog.jspx in the editor.
a n s
n - tr
b. Click the Bindings tab. You should see data bindings, and the Page Definition File
no eฺ
should be listed as oracle/storefront/ui/pages/ProductsPageDef.xml.
a
h a s uid
c. Run the page. The data should now be displayed correctly.
) nt G
d. Close the browser when finished, and undeploy the application as described in step
m
6(i) of Practice 2-4.
l ฺ o
c tude
i
5.
new name of the page. g ma is S
If you have time, as an optional exercise, rename the page definition file to match the

o @ th
c ฺ vin
a. Close JDeveloper, saving any unsaved work and terminating any running processes if
prompted.
( a
A C
b. In Windows Explorer, navigate to your application directory.

n o d c. In the StorefrontUI\adfmsrc\oracle\storefront\ui\pages directory,


V i change the name of ProductsPageDef.xml to ProductCatalogPageDef.xml.

d. Reopen JDeveloper.
e. In the Application Navigator, navigate to StorefrontUI > Application Sources >
oracle.storefront.ui > pages and select ProductCatalogPageDef.xml.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 14
f. In the Structure window, right-click the ProductsPageDef node and select Refactor >
Rename.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

g. In the Rename dialog box, change ProductsPageDef to


ProductCatalogPageDef.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
This changes the ID of the page definition. Alternatively, you could change the ID in the
Property Inspector. a no eฺ
h. a s uid
In the Application Navigator, navigate to StorefrontUI > Application Sources >
h
m ) nt G
oracle.storefront.ui and open DataBindings.cpx.
l ฺ o
c tude
i. i
Map the renamed page definition file to the path of the existing page: In the Page
ma is S
Definition Usages section of DataBindings.cpx, select the path, and then in the
g
@ th
Property Inspector, change the value of the path from ProductsPageDef to
o
ฺ vin
ProductCatalogPageDef.
c
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 15
j. Save your work and then retest the page.
k. Although it is not necessary, if you also want to change the page mapping usageId and
the page definition usages ID, you must edit the XML file manually. This is because
JDeveloper reports an error and will not allow you to declaratively change one of these
values because that would result in an invalid XML document. To change manually:
1) Click the Source tab of the Databindings.cpx editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2) In the <pageMap><page> section, change usageId to


oracle_storefront_ui_ProductCatalogPageDef. The usageId is now
underlined with a red squiggly line indicating an error, because it does not match
the other ID value.

u se
e to
n s
i ce
b l el
fe ra
3) In the <pageDefinitionUsages><page> section, change the id to be the same as s
tr a
the usageId in the previous section. The red squiggly line should disappear.n
n -
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
(4)a If desired, retest the page.
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 11


Chapter 11 - Page 16
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 12
- r
on ฺ
Chaptern12
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 2
Practices for Lesson 12: Planning the User Interface
Practices Overview
You could continue developing pages, but it is usually helpful to plan out the application before
creating all the pages. This enables you to visualize the flow of the application and create a
blueprint for it. You can do this in JDeveloper by creating task flows.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

In the practices for this lesson, you create both unbounded and bounded task flows, along with
various types of activities and control flows for each. You also extract part of an unbounded task
flow into its own flow, and convert an unbounded task flow to a bounded one.
If you successfully completed all sections of the previous practice, you can continue working in
the same project. However, if you prefer to start with a clean application that contains everything
completed up to the start of this lesson, open Storefront-12.jws and edit the database
information as described in step 4 of Practice 2-4.
This practice contains some optional steps that are similar to steps already done. If you want to u se
build the entire application yourself, you can complete the optional steps. However, in the e to
interest of time, you may want to skip them. If you do so, you must begin the practices for the n s
i ce
next lesson by opening the starter application for that lesson.
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 3
Practice 12-1: Creating an Unbounded Task Flow
In this practice, you create activities and control flows in an unbounded task flow. The
application that you are developing is for a storefront, where the main activity is shopping. Users
can peruse a product catalog and add products to their shopping cart. They can then check out
to complete the order.
1. You have already started developing the ProductCatalog page. To begin planning the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

rest of the application, add the ProductCatalog page to the application’s unbounded task
flow.
a. Open the unbounded adfc-config.xml task flow. For convenience, JDeveloper
displays a node for this task flow in two places in the Application Navigator. Expand
StorefrontUI and WebContent. You can then open adfc-config.xml from the
node located under WEB-INF or the one located under Page Flows.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c fromtthe
d e
b. i
Drag ProductCatalog.jspx u Application Navigator to the task flow that is open
in the editor.
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

This creates a view activity in the unbounded task flow.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 4
c. Select the view activity in the task flow editor and look at its Property Inspector. You
can see that it is linked to the ProductCatalog page that you created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
2. Create two additional view activities in theh a s uidtask flow named ProductSearch
unbounded
and ProductDetails. m ) nt G
l ฺ o d eADF Task Flow is selected in the drop-down list
censuretuthat
a. In the Component Palette,
a i S category and drag a View activity to the editor.
at the top. Expandmthe Components
s
g t h i
i n o@
v
( acฺ
d AC
Vi no

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Change the name of the view activity to ProductSearch by entering the new name
either directly on the diagram or in the Property Inspector.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c. c ฺ vin
Similarly, add another view activity named ProductDetails.
( a
A C
n o d
V i

Note the yellow warning symbol on the view activities that you just created. This
means that they do not yet point to pages.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 6
3. Add a Control Flow Case from ProductSearch to ProductDetails and name it detail.
a. Click Control Flow Case in the Component Palette.
b. Click inside ProductSearch, and then click inside ProductDetails.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
c. Enter detail as the name of the case. You can enter directly on the diagram, or it fe ra
may be easier to use the Property Inspector and enter the name as the from- a n s
outcome of the control flow case. n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
4. In the same way, add a Control Flow Case from ProductDetails to ProductSearch and
name it search.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 7
5. Add a Control Flow Case from ProductCatalog to ProductSearch and name it search.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

6. You can move the view activities to make the diagram look better. For example, you can
arrange the view activities as shown:

u se
e to
n s
i ce
b l el
f er a
7. Add a control flow case named detail from ProductCatalog
s
anto ProductDetails.
- t r
on ฺ to ProductCatalog.
8. Add a control flow case named shop from ProductDetails
n
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
v i n
( acฺ
d AC
Vi no
9. Create a fourth View activity named ProductCategory. The page is to display a category
tree for user navigation.
10. Finally, create a View activity called FODShoppingDashboard. The page for this view
activity will be the main page of the application from which all parts of the application are
accessed.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

11. Save your work. u se


e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 9
Practice 12-2: Creating Bounded Task Flows
In this practice, you create bounded task flows for tasks that have defined entry points.
1. Create a bounded task flow for the shopping cart. Create the task flow in the
oracle\storefront\ui\flow subdirectory of Page Flows.
a. Select File > New to invoke the New Gallery.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the Categories list, expand Web Tier and select JSF.


c. In the Items list, select ADF Task Flow and click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
d. In the Create Taskm Flow
i
a dialogSbox:
1) Set File @ g
Name to t h is
intheodirectory path, add \oracle\storefront\ui\flow. This is the path you
ShoppingCartFlow.
v
2) ฺTo
C (ac should use for all task flows.
d A 3) Ensure that Create as Bounded Task Flow is selected.
n o
Vi 4) Ensure that Create with Page Fragments is not selected.

5) Click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 10
e. Note that the newly created task flow appears in the Application Navigator in two
places, both under WEB-INF and under Page Flows.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f. The Shopping Cart flow opens in the editor. Add a view activity and name it
fe ra
ShoppingCart.
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d Note that the view activity is surrounded with a green halo. This indicates that it is the
V i default activity, or entry point, of the task flow. A bounded task flow must have one, and
only one, default activity. Only bounded task flows show default activities, because
unbounded task flows do not have a defined entry point.
g. Add a Task Flow Return and name it Shop.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 11
h. In the Property Inspector for the Shop task flow return activity, set the Outcome name
to shop. This means that when the task flow returns to the one that called it, it
navigates by using a control flow case whose from-outcome is named shop.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
i. - tr
Add a Control Flow Case from ShoppingCart to the Shop task flow return activity
n
and name it too as shop.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 12
j. Similarly, add another task flow return activity called Checkout, with the outcome
name checkout.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
k. s ufrom
Add a control flow case also named checkout
h a id ShoppingCart to Checkout.
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

l. Save your work.


2. Optional step: (If you choose not to create these additional task flows, you must
begin the practices for the next lesson by opening the starter application.)
Similarly, create two additional bounded task flows, being sure to create them in the
\oracle\storefront\ui\flow subdirectory and not to use page fragments: (If in the
Application Navigator, you right-click the WEB-INF > oracle > storefront > ui > flow node,
and then select New; the New Gallery reflects the correct path in the Directory field.)
a. Create the ManageSupplierFlow with:
1) A view activity named SupplierUpdate that is the default activity

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 13
2) A task flow return activity named Save whose outcome is named done
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
3) A task flow return activity named Cancel whose outcome is also named
l i ce done
r a ble
n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o 4) A wildcard control flow rule
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 14
5) Control flow cases between the activities:
From To Name
SupplierUpdate Save save
Wildcard Cancel cancel
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
b. In the same way, create the ShowSuppliersFlow in the n s
a view activity named
\oracle\storefront\ui\flow subdirectory, n -
withtrone
BrowseSuppliers.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 15
Practice 12-3: Extracting Part of a Task Flow
After further consideration, you realize that the product search, details, and catalog function
should be a separate bounded task flow with ProductCatalog as the entry point. In this practice,
you extract part of the unbounded task flow into a separate task bounded task flow.
1. From the unbounded task flow, extract ProductCatalog, ProductSearch, and
ProductDetails into a separate bounded task flow named ShoppingFlow.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Open the adfc-config.xml unbounded task flow.


1) In the Application Navigator, expand StorefrontUI and WebContent.
2) Expand either the WEB-INF or the PageFlows node.
3) Double-click adfc-config.xml to open it in the editor.
b. In the editor, drag a rectangle to encompass the ProductSearch, ProductDetails, and
ProductCatalog view activities, with their control flows.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c.
c ฺ vin
Right-click one of the selected objects and select Extract Task Flow.

( a
A C
n o d
V i

d. On the Extract Task Flow warning, click Yes to accept and proceed.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 16
e. In the Extract Bounded Task Flow dialog box, enter a file name of ShoppingFlow,
add \oracle\storefront\ui\flow to the directory path, and then click OK.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
f. - tr
In the editor, arrange the ShoppingFlow activities in a visually pleasing manner, such
n
as shown below:
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

g. Right-click the ProductCatalog view activity and select Mark Activity > Default
Activity.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 17
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
The ProductCatalog activity is now surrounded with a green halo indicating that it is the
fe ra
default activity, or entry point, for the task flow.
a n s
- tr
h. When you extract a bounded task flow, a task flow call activity is created on the task
n
a no eฺ
flow from which the bounded task flow was extracted. (You may need to look for it in
the diagram, if not visible.) This is not needed, so you can delete it from the adfc-config
task flow. h a s uid
m ) nt G
l ฺ o
1) Open or switch to adfc-config.xml.
c tude
i
g ma is S
2) In the visual editor, right-click the ShoppingFlow activity and select Delete, or you
can delete task-flow-call-ShoppingFlow in the Structure window.
o @ th
c ฺ vin
( a
A C
n o d
V i

i. Save your work.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 12


Chapter 12 - Page 18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 13
- r
on ฺ
Chaptern13
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 2
Practices for Lesson 13: Adding Functionality to Pages
Practices Overview
In the practices for this lesson, you begin to add functionality to pages by using ADF Faces
components. You create search and detail pages and another page that displays a hierarchical
tree of categories and subcategories. You also create several pages that display input
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

components as a list of values.


If you successfully completed all sections of the previous practice, including the optional steps,
you can continue working in the same project. However, if you prefer to start with a clean
application that contains everything completed up to the start of this lesson, open
Storefront-13.jws and edit the database information as described in step 4 of Practice 2-4.
This practice contains some optional steps that are similar to steps already done. If you want to
build the entire application yourself, you can complete the optional steps. However, in the
interest of time, you may want to skip them. If you do so, you must begin the practices for the u se
next lesson by opening the starter application for that lesson.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 3
Practice 13-1: Creating a Table with Row Selection
In this practice, you create the Shopping Cart page. This page displays the items in a user’s cart
(those order items for the user whose status is CART).
1. Create the ShoppingCart page.
a. Open ShoppingCartFlow in the editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Double-click the ShoppingCart view activity.


c. In the Create JSF Page dialog box, ensure that Create as XML Document is selected,
so that the file that is created can be used as metadata. (This option should be
selected and disabled.)
d. Leave the file name as ShoppingCart.jspx.
e. To the Directory path, append \oracle\storefront\ui\pages, and then click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i 2. Create a read-only table on the page to display the user’s cart, showing the product name,
list price, quantity, and line total of items that are ordered. Users should be able to use a
mouse to select a line item.
a. The ShoppingCart page opens in the editor. From the Data Controls panel, drag
FODShoppingCartAMDataControl > ShoppingCart1 > ShoppingCartItem1 to the
page as a Table > ADF Read-only table.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
b. Ensure that Row Selection is enabled.
i ce
c. Delete all but the following attributes and arrange them in order:
b l el
ProductName
fe ra
a n s
ListPrice
n - tr
no eฺ
Quantity
LineTotal a
s uid
h a
) nt G
o m
c tude
i l ฺ
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Note: Select and remove the other attributes by clicking Delete. You can reorder the
attributes by selecting an attribute and using the up and down arrows as required.
Hint: An easy way to reorder many attributes is to first select the last attribute that you
want in the display (in this case, LineTotal) and click the top arrow, which places the
attribute at the top of the list. Then select the next-to-last attribute (in this case
Quantity) and place it at the top of the list. Continue with all the attributes, from last to
first. Finally, select all the other attributes and delete them.
d. Click OK.
3. Test the page.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 5
a. Right-click the editor for the ShoppingCart page and select Run.
b. If necessary, in the Confirm Run JSF JSP dialog box, click Yes.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Note: You receive this message because you are running the page directly instead of
running it within the context of the bounded task flow. You do not need to use the ADF
u se
Controller in this case because you are not using any control flows to test this single
e to
page. In most cases, however, you should run pages from a task flow rather than
n s
running them directly. i ce
You also receive several compilation warnings: XML-24521: (Error) Element not b l el
fe
completed: 'view', because you have created several activities in task flows that have ra
n
not been completed, such as view activities without corresponding pages. You can
a s
safely ignore these warnings.
n - tr
c. no eฺ
The page runs, but does not show any data. ShoppingCart is tied to a specific user;
a
h a s uid
however, you have not yet told it what user.

m ) nt G
l ฺ o
c tude
i
g ma is S
d. Close theo
n @ whenthyou have finished and undeploy the application as described
browser
i
ฺv 6(i) of Practice 2-4.
in step
a c
4. Add( to the page an invocation of the application module’s init() method that initializes
d ACthe application to show shopping cart data for a specific user. The method interrogates the
n o system user (a hard-coded name is used until security is implemented in a later practice)
Vi and uses that name as the username for the shopping cart. Hint: This involves adding a
method action binding and an invoke action binding to the page definition.
a. Click the Bindings tab in the editor for the ShoppingCart page.
b. Add a Method Action binding to the init() method in the
FODShoppingCartAMDataControl:

1) In the Bindings section, click Add .

2) In the Insert Item dialog box, select methodAction and click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 6
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
3) In the Create Action Binding dialog box, select b l el
FODShoppingCartAMDataControl, choose init() from the Operation drop-
fe ra
down list, and then click OK.
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

c. Add an InvokeAction to the executables that runs init(). Name it invokeInit


and set the Refresh property to ifNeeded. Make sure that it is the first executable so
that it runs before the iterator.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 7
1) In the Executables section, click Add .
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2) In the Insert Item dialog box, select invokeAction, and then click OK.
3) In the Insert invokeAction dialog box:
Enter an ID of invokeInit, select init from the Binds drop-down list, and click
OK. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
4) In the Property Inspector, set Refresh ton o ฺ
ifNeeded.
s a i d e
a
) h nt G u
m
co tude
i l ฺ
g ma is S
o@ th
i n
(a cฺv
C 5) In the Executables panel, drag the invokeInit executable to the top position, so
d A that the init() method is invoked before the iterator.
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 8
d. Save your work and run the page again to check that you can see items in the
shopping cart.
You should be able to select any row in the table, and the page should look similar to
the following:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

e. Close your browser when you have finished and undeploy the application as described
in step 6(i) of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 9
Practice 13-2: Creating a Search Page
In this practice, you use a query component to create a search page, and you test its
functionality.
1. Create the ProductSearch page.
a. Open ShoppingFlow in the visual editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Double-click the ProductSearch view activity.


c. In the Create JSF Page dialog box, ensure that Create as XML Document is selected,
so that the file that is created can be used as metadata. (This option should be
selected and disabled.)
d. Leave the file name as ProductSearch.jspx.
e. To the Directory path, append \oracle\storefront\ui\pages, and then click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i 2. Add a query component to the ProductSearch page to query for products. The search
results should appear in a table that shows product name, category name, list price, and
description. The user should be able to select a row.
a. The ProductSearch page opens in the editor. Drag FODProductAMDataControl >
BrowseProduct > Named Criteria > SearchByName to the page in the editor and
select Query > ADF Query Panel with Table from the context menu.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b. In the Edit Table Columns dialog box:
b l el
1) Enable Row Selection.
fe ra
2) Include only the following four attributes in this order:
a n s
ProductName
n - tr
CategoryName
a no eฺ
ListPrice
h a s uid
Description m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 11
3) Click OK. The page should look similar to the following:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
3. Test the functionality of the ProductSearch page. e to
n s
a. Right-click the editor for the ProductSearch page and select Run. (Do not run the i ce
page from the task flow because the default activity of the task flow does not yet have
b l el
the ability to navigate to the ProductSearch page.)
fe ra
NOTE: Although this page is represented as a view activity on the bounded task flow
a n s
n - tr
that is not the default activity, you can still run the page separately when you are not

individual pages. a no eฺ
running it from the task flow. It is the task flow that has a single entry point, not

h a s uid
b. The page runs and looks similar to the following:
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Note that the table does not fill up the page. You must scroll to see all the columns.
You later improve the look of the table in the practice for the lesson titled “Achieving the
Required Layout.”
c. Experiment with the functionality of the page.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 12
1) Enter a percentage sign (%) in the ProductName field and click Search. All of the
products appear.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
2) Resize columns in the table
o m e n t Gthe lines between the column headers.
)by dragging
c tabletubyddragging column headers.
ilฺthe
3) Reorder columns in
a
m is S
g th
i n o@
ฺv
C (ac
d A
n o
Vi 4)
5)
Click Advanced to enable more search options.
Select Contains from the operators drop-down list.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 13
6) Enter Pla in the ProductName search field and click Search. Note that the table
displays products that contain “Pla.”
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
7) Select “Does not contain” from the operators drop-down list and click Search.
e to
Now the table displays only those products that do not contain the string “Pla.”
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 14
8) Select Price from the Add Fields drop-down list.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
9) For the Price criterion, select “Greater than” from the operators drop-down list,
b l el
enter a value of $1000 (ListPrice is formatted as currency), and then click Search.
fe ra
n s
Now the table displays only those products that do not contain the string “Pla” and
a
whose list price is more than $1000.
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
10) When you have finished, close the browser and undeploy the application as
described in step 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 15
Practice 13-3: Creating a Read-Only Form
In this practice, you create the ProductDetails page. This page displays the details of the
product that the user selects on the ProductSearch page. Later, in the practices for the lesson
titled “Implementing Navigation on Pages,” you add a button to the ProductSearch page that
navigates to the ProductDetails page.
1. Create the ProductDetails page on the ShoppingFlow task flow.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Open ShoppingFlow from the Application Navigator if it is not already open.


b. Double-click the ProductDetails view activity, or right-click it and select Create Page.
c. Create a .jspx page in the directory where you are creating pages
\oracle\storefront\ui\pages.
2. Add a read-only form to the ProductDetails page to display details of the selected product,
including product name, category name, and list price.
a. Drag the Data Control FODProductAMDataControl > BrowseProduct to the visual
u se
editor and select Form > ADF Read-only form from the context menu.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c box: d e
i t u
b.
ma is S
In the Edit Form Fields dialog
1) Include onlygthe following
o @ t h fields in order:
ฺ in
vCategoryName
ProductName
(a c
A C ListPrice
n o d
Vi Note: Select and remove the other attributes by clicking the icon. The attributes can
be reordered by selecting an attribute and using the up and down arrows as required.
2) Do not include Submit Button or Navigation Controls.

3) Click OK. The page should look similar to the following:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 16
3. Run the page to test it. Run it directly rather than from the task flow because you have not
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

added navigation yet. The page should look similar to the following, displaying only one
record, which may not be the same as the record shown:

4. When you have finished, close the browser and undeploy the application as described in
step 6(i) of Practice 2-4.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 17
Practice 13-4: Creating a Sortable Table
In this practice, you create the BrowseSuppliers page that enables users to sort the table on any
of its columns. This practice is optional because the steps are similar to what you have done
previously. If you choose not to create the BrowseSuppliers page, you must begin the practices
for the next lesson by opening the starter application.
1. Create the BrowseSuppliers page on ShowSuppliersFlow.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. From the Application Navigator, open ShowSuppliersFlow.


b. Open the BrowseSuppliers page, being sure to create it in your
\oracle\storefront\ui\pages directory.
2. Create a read-only table on the page to list the suppliers, displaying the supplier ID, name,
status, phone number, and email address. The table should be sortable, and users should
be able to select a row.
a. From the Data Controls panel, drag to the page FODSupplierAMDataControl >
Supplier1 as a Table > ADF Read-only Table. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
a
b. (Use only the first five attributes.
C
A c. Enable Row Selection and Sorting.
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 18
3. Test the page.
a. From either the page editor or the task flow, run the BrowseSuppliers page. It should
look similar to the following:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Test that you are able to sort columns and select rows.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
c. When you have finished, close the browser a no eฺ the application as described
and undeploy
in step 6(i) of Practice 2-4. h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 19
Practice 13-5: Creating a Category Tree
In this practice, you create the ProductCategory page, and then create on it a tree that shows
product categories with their subcategories.
1. Create the ProductCategory page on the unbounded task flow.
a. Open adfc-config.xml from the Application Navigator.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. You may have to scroll in the diagram to see the existing views, and then either
double-click the ProductCategory view, or right-click it and select Create Page.

u se
e to
n s
i ce
c. Create a .jspx page in the directory where you are creating pages
b l el
(\oracle\storefront\ui\pages).
fe ra
2. Add a tree to the ProductCategory page to display categories and subcategories.
a n s
- tr
a. From the Data Controls panel, drag to the page FODCategoryAMDataControl >
n
RootCategory1 as a Tree > ADF Tree.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 20
b. In the Edit Tree Binding dialog box, select SubCategory from the Add Rule drop-
down list.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Select the oracle.fod.storefront.uiview.RootCategoryVO(<SubCategory>) tree level u se


rule. e to
n s
d. Shuttle CategoryName from the Available Attributes list to the Display Attributes list, i ce
and remove CategoryDescription from the Display Attributes list.
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d e. Now, select the oracle.fod.storefront.uiview.BrowseSubCategoryVO tree-level rule.
V i Shuttle CategoryName from the Available Attributes list to the Display Attributes list,
and remove CategoryDescription from the Display Attributes list.

f. Click OK to create the binding.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 21
Note: This shows up at run time as a hierarchical tree with nodes and subnodes
displaying category names and subcategory names. Note that both RootCategoryVO
and BrowseSubCategoryVO are based on the same entity object, ProductCategoryEO.
The queries are differently defined to select those with no parent category for
RootCategoryVO and all categories for BrowseSubCategory. The view link defined to
link the two view objects restricts the second view to display only those subcategories
whose parent category is the root category. This becomes clearer when you run the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

page.
g. The page should look similar to the following:

u se
e to
n s
3. Convert the output text to a command link. i ce
a. On the ProductCategory page, select af:outputText in either the Structure window b l el
or the visual editor. (You must keep expanding the af:tree node all the way to find fe ra
a n s
b.
af:outputText.)
n - tr
Right-click af:outputText and select Convert To.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

c. In the Convert Output Text dialog box, select Link.


d. Click OK. You will get a Confirm Convert dialog box informing that the Value attribute
will be removed. Click OK to continue.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 22
e. In the Properties Inspector, set the Text to #{node}. (You can use Expression
Builder and select the expression from JSP Objects.)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

4. Test the ProductCategory page.


a. Run the ProductCategory page from either the page editor or from the task flow. The
page should look similar to the following when you expand the category nodes:
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
@ th
ฺ v ino
b. a c that you can expand the nodes, but nothing happens when you click the links
Note
(other than that the tree is refreshed. You change this behavior in a later practice.
A C
n o d c. When finished, close the browser and undeploy the application as described in step
V i 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 23
Practice 13-6: Creating LOVs
In this practice, you create pages with input components that use lists of values. Input
components automatically use LOVs when the model specifies that an LOV be used for display
of an attribute.
1. In the data model, review how a list of values was defined for SupplierVO.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, expand the StorefrontModel project.


b. Expand Application Sources > oracle.fod.storefront > uiview.
c. Double-click SupplierVO to open it in the editor.
d. Click the Attributes tab.
e. Select the SupplierStatus attribute.
f. In the List of Values section in the lower portion of the editor, open the List of Values
node, and then select LOV_SupplierStatus and click Edit.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
g. In the List of Values editor:
h a s uid
1) Click the Configuration tab,)where you
o m e n t Gcan see that SupplierStatus will be
selected from the available
i l ฺ cLookupCode
LookupCode
t u d rows in the LookupCodeVVO1 view

g
attribute when mthea userisselects
accessor, and that the value will be
S a value from the list. returned to the SupplierStatus
th where you can see that the attribute appears as a Choice
othe@UI Hints tab,
2) Clicki n
v containing the LookupCode and Description.
(a cฺList
d AC 3) Click Cancel.
Open SupplierEO under the StorefrontModel > Application Sources >
Vi no h. oracle.fod.storefront > entity node.
i. Click the View Accessors tab.
j. Select LookupCodeVVO1, and then click Edit.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 24
k. You can see that the view accessor limits the view to those rows where the lookup type
is SUPPLIER_STATUS_CODE.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

l. Click Cancel to close the window, and then close the EO and VO editors.
2. In the ManageSupplierFlow task flow, create the SupplierUpdate page, using an LOV for
the SupplierStatus attribute. Place this page in a \supplier subdirectory where you have
been creating pages (\oracle\storefront\ui\pages). The form needs to show only
one record. u se
a. Open the ManageSupplierFlow task flow from the Application Navigator if it is not e to
n s
already open.
i ce
b. Create the SupplierUpdate page, placing it in a supplier subdirectory
b l el
\oracle\storefront\ui\pages\supplier.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 25
c. Drag the data control FODSupplierAMDataControl > Supplier1 to the page and
create an ADF Form.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
d. Select only the following fields:
i ce
SupplierName
b l el
SupplierStatus
fe ra
a n s
PhoneNumber
n - tr
noButton.
Email

a s a
Do not include Navigation Controls or a Submit
i d eฺ
) h t Gu
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi Click OK. Note that the “Component to Use” field for the SupplierStatus attribute is
ADF Select One Choice; this is determined by the setting in the ADF BC model.
Although you can change the setting here, it is better to let the model determine the list
type.
The page should look something like the following:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 26
e. Test the page by running it directly. The page should look similar to the following with
the list of values dropped down:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 27
Practice 13-7: Setting Up the UI Project for Internationalization
So far all of the text in the user interface is bound to data in the ADF BC model. Soon you begin
to add text that you enter into the application yourself. To make sure that this text is translatable,
you store it in a resource bundle. In this practice, you set up the UI project to use a resource
bundle.
1. Set up the project to use a single Properties Bundle file per project.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Right-click the StorefrontUI project in the Application Navigator and select Project
Properties, or just double-click the node to open the Project Properties editor.
b. In the list at the left of the Project Properties editor, select Resource Bundle. Make
sure that the Resource Bundle Type property is set to Properties Bundle and select
the One Bundle Per Project option. If necessary, set the Default Project Bundle Name
to oracle.storefront.ui.StorefrontUIBundle.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
(a
C
A c. Click OK.
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 13


Chapter 13 - Page 28
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 14
- r
on ฺ
Chaptern14
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 2
Practices for Lesson 14: Implementing Navigation on Pages
Practices Overview
So far you have created several pages that are part of task flows, and you have created control
flows between them with outcomes that can be used for navigation. However, you have not
implemented navigation on the pages, so there is no mechanism for moving from one activity to
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

the next within task flows.


In this set of practices, you implement navigation on pages by creating buttons, links,
breadcrumbs, and a train.
If you successfully completed all sections of the previous practice, including the optional steps,
you can continue working in the same project. However, if you prefer to start with a clean
application that contains everything completed up to the start of this lesson, open
Storefront-14.jws and edit the database information as described in step 4 of Practice 2-4.
This practice contains some optional steps that are similar to steps already done. If you want to u se
build the entire application yourself, you can complete the optional steps. However, in the e to
interest of time, you may want to skip them. If you do so, you must begin the practices for the n s
i ce
next lesson by opening the starter application for that lesson.
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 3
Practice 14-1: Creating Buttons for Navigation
In this practice, you create buttons on pages and set the Action property of the buttons to
correspond to a from-outcome of a control flow rule in the task flow. Then when the user
clicks the button, the navigation takes place. You create labels for the buttons as translatable
strings in the Bundle rather than as hard-coded values.
1. The ManageSupplierFlow task flow has a global control flow rule whose from-outcome is
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

cancel. Add a Cancel button to the page in the task flow to implement this global rule.
Create the label for the button as a translatable string.
a. Open the ManageSupplierFlow task flow by double-clicking it in the Application
Navigator. (The task flows are located under the Web Content > Page Flows > oracle
> storefront > ui > flow node.)
b. Double-click the SupplierUpdate view activity to open the page in the editor.
c. In the Component Palette, ensure that ADF Faces is selected from the drop-down list,
and drag a Button to the page just inside the top of the form in the editor. u se
(You may find it easier to drag it to the Structure window—expand af:form and drag e to
the button just above af:panelFormLayout.) n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
The page o should th to the following:
@ look similar
v i n
( acฺ
AC
d
V ino

d. To define text for the button label and store it in a resource bundle, in the Property
Inspector, click the arrow to the right of the Text property and select Select Text
Resource from the context menu.

(Alternatively, you can right-click the button in the editor or in the Structure window and
select Select Text Resource for > Text from the context menu.)
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 4
e. In the Select Text Resource dialog box:
1) Ensure that StorefrontUIBundle is the selected resource bundle.
2) Enter a Display Value of Cancel, which populates the Key value with CANCEL.
3) Enter a Description of Label for the Cancel button.
4) Click Save and Select.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
f. o @ th
The label of the button changes to Cancel.
c ฺ vin
Note: The label of the button may appear at design time as the EL expression
( a
A C #{storefrontuiBundle.CANCEL}.

n o d
V i

g. Select the button and in the Property Inspector, click the Action drop-down list and
select cancel.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 5
This ensures that the cancel control flow is executed when the user clicks the Cancel
button.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

h. To enable users to cancel and leave the form without entering the required fields, set
the Immediate property to true on the Behavior panel of the Property Inspector.

2. Optional step: (If you choose not to create this button, you must begin the practices
for the next lesson by opening the starter application.) u se
The ManageSupplierFlow task flow has a control flow rule from SupplierUpdate to the Save e to
task flow return activity whose from-outcome is save. Follow a similar series of steps to n s
i ce
add a Save button just to the right of the Cancel button on the SupplierUpdate page to
implement this navigation. Create the label for the button as a new translatable string and b l el
select the save action. Do not change the default value of the Immediate property for thisfe ra
button. a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 6
3. Similarly, in the ShoppingFlow task flow, open the ProductCatalog page. Add a button
above the panelHeader component, and using the Text Resource, label it Search. Set the
Action to search.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
ice
b l el
4. Optional step: (If you choose not to create these buttons, you must begin the fe ra
practices for the next lesson by opening the starter application.)
a n s
- tr
Following a similar series of steps, add the following buttons for navigation, optionally using
n
a text resource for the label of each:
a no eฺ
Task Flow Page
h a s Buttonu idLabel Button
m ) nt G Action
l ฺ o
c tude Search (use the
i
ma is S
ShoppingFlow ProductDetails search

@ g t h existing text resource)

ino
ShoppingFlow
ฺ v ProductDetails Shop (create a text shop

( ac resource entry)

d ACShoppingCartFlow ShoppingCart Shop (use the existing shop

V ino text resource)


ShoppingCartFlow ShoppingCart Checkout (create a checkout
text resource entry)
Save your work.
5. Examine the resource bundle.
a. In the Application Navigator, expand StorefrontUI > Application Sources >
oracle.storefront.ui.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 7
b. Double-click StorefrontUIBundle.properties to open it in the editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. The file should look similar to the following (not all of these entries are present if you
skipped any optional steps):

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
Note: Although subsequent practices ) nspecify
t G the use of a resource bundle to
store translatable strings,oinm the interest of time, you may choose to just enter
i
the strings as hard-codedl ฺ c text.tude
d. Close all editor g ma is S
windows.
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 8
Practice 14-2: Creating Links for Navigation
In many cases, you want the user to be able to click some text, such as a product number, to
navigate to another page. In this practice, you create links that implement navigation.
1. The ShoppingFlow task flow has a control flow rule from ProductSearch to
ProductDetails whose from-outcome is detail. You want users to be able to click
the ProductName on the ProductSearch page to drill down to the details about the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

products. Convert the ProductName on the ProductSearch page to a link that implements
this navigation. Clicking the link should not select a row.
a. Open the ProductSearch page.
b. Turn off automatic row selection on the table:
1) Select af:table in the Structure window or in the breadcrumbs at the bottom of the
editor.
2) Click Edit on the Property Inspector.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) box, n G
tdeselect
3) In the Edit Table Columnso
c tud dialog e the Row Selection check box, and
then click OK. ailฺ
c. g m isto S
Change the ProductName be a link that calls the ADF method that sets the row and
@ t h
noStructure
then navigates
vithe
1)cฺIn
to the detail page:
window, expand the first af:column under af:table.
C (a
2) Right-click af:outputText for ProductName in the Structure window and select
d A Surround With.
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 9
3) In the Surround With dialog box, select ADF Faces > Link and click OK.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
4) In the Property Inspector, remove the value in the Text property of the
b l el
af:commandLink and set Action to detail.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
a
d. (If you run the page from the task flow at this point (see step f below for how to do that if
C
A you want to try), the link navigates to the detail page but always displays details for the
n o d
V i first product. The reason for this behavior is that when you disabled row selection you
also disabled row concurrency. Add a method called setCurrentRowWithKey that
sets the row of the Product iterator to whatever the current row is on the page.
1) In the Data Controls panel, expand FODProductAMDataControl >
BrowseProduct > Operations.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 10
2) Drag the setCurrentRowWithKey operation to the af:commandLink in either
the Structure window or the editor, and select Bind Existing Link.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
3) Click OK to closeathe EditS Action Binding dialog box.
g m i s
4) In the Confirm th Rebinding dialog box, select the Keep Current Value
@ forComponent
oboxes
i n
check
ฺv the text and action properties. Click OK.

C (ac
d A
n o
Vi

e. The setCurrentRowWithKeyValue method uses an argument (ND or Named Data) to


tell it which row is current. The collection model for the table knows which row is
selected and maintains a property named rowKeyStr, which holds the key to the
current row. Use this as an argument to setCurrentRowWithKey, which in turn
resets the BrowseProductIterator to reflect the correct row:
1) Right-click anywhere on the ProductSearch page and select Go To Page
Definition, or click the Bindings tab of the page.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 11
2) In the Structure window, select bindings > setCurrentRowWithKey > rowKey.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

3) In the Property Inspector, set the NDValue property to #{row.rowKeyStr}, and


then click in any other field to apply this value, or press Tab or Enter. (By
changing field focus, the IDE accepts the value that you entered.)
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
f. Test the links in the ShoppingFlow task flow. a no eฺ
1) In the ShoppingFlow task flow, h a s
right-click u idProductCatalog view activity and
the
select Run. m ) nt G
l ฺ o
c page,tuclick
d eSearch.
2) On the ProductCatalogi
a enterS% in the ProductName field and click Search.
3) On the Search g mpage, isthe link on the product name.
@ t h
ฺ v ino
Experiment with using

C (ac
d A
n o
Vi
4) If you did not complete the optional steps of defining additional buttons, click the
Back button of your browser, otherwise perform the following actions:
a) On the detail page, click Search to return to the search page to try another
link.
b) On the ProductDetails page, click Shop to return to the ProductCatalog page.
5) When you have finished, close the browser and undeploy the application as
described in step 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 12
2. In the ShoppingFlow task flow, add a drill-down link from the ProductCatalog page to the
ProductDetails page.
a. Open the ProductCatalog page.
b. Select the af:outputText of ProductName in the bottom table.
c. Press Ctrl + C to copy the Value property #{row.ProductName}.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

d. Right-click the af:outputText and select Convert To. u se


e. In the Convert Output Text dialog box, select ADF Faces > Link and click OK. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
@ th
ฺ v ino
( ac OK to confirm Convert.
Click
C
A f. Paste the copied value into the Text property of the commandLink.
d
V ino

3. Coordinating the ProductCatalog and ProductDetails pages is made more complex by the
fact that the two pages use different iterators. The ProductDetails page uses the top-level
BrowseProduct iterator, whereas the ProductCatalog page uses the BrowseProduct1
iterator that is a detail of BrowseCategory > BrowseSubCategory. Therefore, you must use
the setCurrentRowWithKeyValue() method from the BrowseProduct data control to
coordinate the pages.
a. In the Data Controls panel, expand FODProductAMDataControl > BrowseProduct >
Operations.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 13
b. Drag setCurrentRowWithKeyValue to the af:commandLink you just converted and
select Bind Existing Link.
Note: Ensure that you select setCurrentRowWithKeyValue, and not just
setCurrentRowWithKey.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. In the Edit Action Binding dialog box, click OK. u se


d. In the Confirm Component Rebinding dialog box, select the text check box to retain its e to
value and click OK. n s
i ce
b l el
fe ra
a n s
n - tr
e. Select af:commandLink and set the Action
o ฺ to detail.
nproperty
s a i d e
4. The setCurrentRowWithKeyValue method
) a
h tG usesuan argument (ND or Named Data) to

c o m en
tell it which row is current. The argument for setting the current row of Product is ProductId.

ail tableSfor d
tuthis page, you excluded the ProductId because you
When you created them Product
do not want to display
@ g t
it. Because
s
hi it was excluded, it is not in the page bindings. Before you
o
ฺvinit to theasbindings.
can use ProductId
haveatocadd
an argument to the setCurrentRowWithKeyValue method, you
After you add it, you can set the NDValue property of
(
d ACsetCurrentRowWithKeyValue.

Vi no a. Go to the Overview tab of the ProductCatalog page definition, or to the Bindings tab
of the page.
b. In the Bindings section, select the BrowseProduct1 binding and click Edit.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 14
c. In the Attributes section of the Tree Binding Editor, shuttle the ProductId from the
Available Attributes to the Display Attributes, and then click OK.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
page. It simply makes thec o m) available
Note: This adds the attribute to the
attribute e n tG
bindings, but it does not add it to the table on the
to the page.
d. a ilฺ Stud method uses an argument (ND or Named Data)
The setCurrentRowWithKeyValue
g m is The argument for setting the current row of Product is
to tell it which row
@ h
is current.
t
In c ฺ
the
ino window, select bindings > setCurrentRowWithKeyValue > rowKey
ProductId.
vStructure
C (a
and set the NDValue property to #{row.ProductId}. Be sure to tab out of the field or

n o dA click in another field so that the value is saved.


V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 15
e. Test the page by running it from the ShoppingFlow task flow. (Open the task flow,
right-click the default activity, and select Run.) Remember that the Products table is
not yet coordinated with the Categories and Subcategories tables, so just scroll to the
bottom table and try out the ProductName links.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. Click Shop to return to the ProductCatalog page to try different links. (If you did not
define the Shop button in the optional steps, use the browser’s Back button to return to
the ProductCatalog page.)
u se
Note: If the Products table at the bottom shows no data, you can test the links after
e to
you coordinate the Products table with the Subcategories table in a later practice.
n s
i ce
el
g. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.
a b l
5. On the ShowSuppliersFlow task flow, create a task flow call activity to invoke the fe r
ManageSupplierFlow task flow, a control flow case named update from BrowseSuppliers a n s
n - tr
to ManageSupplierFlow, and a control flow case named done from ManageSupplierFlow to
no eฺ
BrowseSuppliers. You want users to be able to click the SupplierId to be able to update the
a
h a s uid
supplier. Convert the SupplierId on the BrowseSuppliers page to a link that implements this
) nt G
navigation. You do not need to disable row selection for this table.
m
o
c tude
a. Open the ShowSuppliersFlow task flow.
l ฺ
i
ma is S
b. From the Application Navigator, drag ManageSupplierFlow to the diagram to create a
g
o @ th
task flow call activity.

c ฺ vin
( a
A C
n o d
V i

c. Create a control flow case from BrowseSuppliers to ManageSupplierFlow and set its
from-outcome to update.
d. Create a control flow case from ManageSupplierFlow to BrowseSuppliers and set its
from-outcome to done. (It should default to done because that is the outcome of the
task flow return activities in ManageSupplierFlow.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 16
e. Open the BrowseSuppliers page.
f. Change the SupplierId to be a link that navigates to the SupplierUpdate page:
1) In the Structure window, expand the first af:column under af:table.
2) Right-click af:outputText for SupplierId in the Structure window and select
Surround With.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
3) In the Surround With dialog box, select ADF Faces > Link and click iOK.
l ce
4) In the Property Inspector of the af:commandLink:
r a ble
a) Remove the value in the Text property
n s fe
b) Set the Action to update
n - tra
5) On the Behavior tab, set the PartialSubmit
a noproperty
e ฺ
to true.
g. Test the page by running BrowseSuppliers
a s from
u i the
d ShowSuppliersFlow
h t toGthe supplier update page.
When you click a link, you should) navigate
task flow.

m
co tuden
i l ฺ
g ma is S
i
However, n othe@page doesthnot yet commit any updates you may make for the selected
v
( acฺ you implement that in a later practice.
supplier;
AC
h. When you have finished, close the browser and undeploy the application as described
d in step 6i of Practice 2-4.
V ino

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 17
Practice 14-3: Using Breadcrumbs
In this practice, you add breadcrumb navigation to the ProductCatalog page. This application
uses explicitly defined breadcrumbs, rather than those that are tied to the XML Menu Model. In
this exercise, you define the breadcrumbs component and one navigation item. Later, in the
practice for the lesson titled “Passing Values Between UI Elements,” you add dynamic
navigation items to this breadcrumbs component by using parameters.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Open the ProductCatalog page from the ShoppingFlow diagram.


2. Drag a Bread Crumbs component from the Component Palette to the Structure window,
just below the af:form component and above the af:commandButton. It should be the first
component in the form.

u se
e to
n s
i ce
b l el
f er a
3. Drag three Navigation Items to the af:breadCrumbs component. an s
- t r
n a resource bundle to change its
4. Select the first af:commandNavigationItem andouse
Text property to Store, or optionally, just entera n
the text. eฺ
h
5. You will not be able to test the navigation a s
until after u idadd the dynamic breadcrumbs
you
functionality in a later practice. Form
o now,
e t Gthe other two navigation items as they
) justnleave
are.
a ilฺc Stud
g m is
o@ th
v i n
( acฺ
d AC
Vi no

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 18
Practice 14-4: Defining a Sequence of Steps
Another way to implement navigation is to use a Train component to manage the navigation for
you. This is particularly useful when there is a set navigation path and order. This is the case
with the CheckoutFlow.
In this practice, you define the CheckoutFlow task flow. Because checking out at the end of a
shopping session is a series of steps, you implement this task flow as a train, and you add a
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

train component to the first page in the train. In the later practice for the lesson titled “Ensuring
Reusability,” you use a page template for the pages.
1. From the StorefrontUI project, invoke the New Gallery.
2. Select Web Tier > JSF > ADF Task Flow and click OK.
3. In the Create Task Flow dialog box:
a. Enter a File Name of CheckoutFlow.
b. To the Directory path, append \oracle\storefront\ui\flow.
u se
c. Ensure that Create as Bounded Task Flow is selected.
e to
d. Ensure that Create with Page Fragments is not selected. n s
i ce
e. Select the Create Train check box.
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

f. Click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 19
4. Create the following three View Activities on CheckoutFlow, and note that because of the
train choice, JDeveloper creates a navigation path as you create the activities:
CheckoutShipping
CheckoutPayment
CheckoutConfirm
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

5. Add two task flow returns:


a. Name one task flow return SubmitOrder, and set the name of its outcome in the
u se
Property Inspector to submit.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
b. Name the other task flow return CancelOrder,a noandesetฺ the name of its outcome in the
Property Inspector to cancel.
h a s uid
c. Add a wildcard control flow m ) nt G
rule.
l ฺ o
c tude
d. i
Add two control flow cases:
ma from
1) One namedgsubmit i s SCheckoutConfirm to SubmitOrder
t h
o@ cancel from the wildcard to CancelOrder
2) One
ฺv i nnamed

C (ac
d A
n o
Vi

6. Create the CheckoutShipping page:


a. Double-click the CheckoutShipping view activity to create the page. Ensure that you
create the page in the \oracle\storefront\ui\pages directory.
b. Add a form that displays the ShippingAddress information:
1) Drag FODCheckoutAMDataControl > ShoppingCart1 > ShippingAddress to
the page (or to af:form in the Structure window) as an ADF Form.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 20
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2) Include the following attributes in order, deleting all other attributes:


Address1
Address2
City
StateProvince
PostalCode
CountryId
u se
3) Do not include Navigation Controls or a Submit Button.
e to
4) Click OK to create the form. n s
i ce
7. Run the page from the CheckoutFlow task flow. It has no data on it because the shopping
cart context has not been established. Also note that there is currently no means of b l el
navigation. You fix these problems in the next steps. fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
When finished, close the browser
l ฺ o and
d e the application as described in step 6(i) of
c tuundeploy
i
Practice 2-4.
ma is S cart by calling the init() method defined in the
8. Establish the contextgfor thetshopping
o@ h
i n
FODCheckoutAMDataControl
ฺ v execute the method as application module. Add a reference to the init()
methodcand
( a the current username (nowpart
retrieves hard
of the page load process. This init() method
coded, but when security is implemented will be
A C
nod
set programmatically), sets the value in a named WHERE clause, and then reexecutes the
Vi query. The result is that the shopping cart is populated with data from the current user.
To use the init() method, you define a reference for it in the page definition file. Then
you add an invokeAction to the page definition executables. invokeAction executes
when the page is loaded.
a. Open the Page Definition for the CheckoutShipping page (right-click anywhere on
the page and select Go To Page Definition), or click the Bindings tab on the page.
b. Click the Add icon (green plus sign) on the Bindings pane.

c. In the Insert Item dialog box:


1) Select Generic Bindings from the drop-down list.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 21
2) Select methodAction.
3) Click OK.
d. In the Create Action Binding dialog box:
1) Select FODCheckoutAMDataControl. Note that the Operation defaults to
init(). This is because the init() method is the only method in the application
module.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
2) Click OK. e to
n s
e. Now that you have a reference to the init() method, you can add it to the i ce
Executables list:
b l el
1) Click Add in the Executables section. fe ra
2) Select Generic Bindings > invokeAction and click OK. a n s
n - tr
3) In the Insert InvokeAction dialog box, set id to invokeInit, and set Binds to init,
and then click OK. a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
a
(4) In the Property Inspector, set the Refresh property to ifNeeded.
C
A Note: By setting the Refresh property to ifNeeded, the framework refreshes the
n o d
V i executable when it has not been refreshed to this point. For example, when you have
an accessor hierarchy in which a detail is listed first in the page definition, the master
could be refreshed twice (once for the detail and again for the master's iterator). Using
ifNeeded avoids duplicate refreshes.
5) Drag the invokeInit action so that it is first in the list of executables.

9. Add the ability to navigate to the next page by adding a Train component to the page. The
Train component shows the user’s relative position in the train. It has train stops (small
boxes) for each of the pages in the train. The current position is highlighted with a slightly
larger box. The Train component can also be used for navigation. The user can click the
previous or next train stop to navigate to that page.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 22
a. In the page editor for the CheckoutShipping page, drag a Train component from the
Component Palette just inside the top of the form.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the Bind Train dialog box, click OK to accept the default trainModel to bind to.
10. Add a train button bar to the page. A train button bar displays Back and Next buttons to
navigate to the next or previous train stop.
a. Drag a Train Button Bar from the Component Palette to the Structure window just
after the af:train.
u se
b. In the Bind trainButtonBar dialog box, click OK to accept the default trainModel to
e to
bind to. n s
Note: Ensure that the train button bar appears in the Structure window between the i ce
train and the panel form layout. The Structure window should look like this (if not, drag b l el
components to rearrange them):
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d11. Add labels for the train stops: Shipping, Billing, and Confirmation. JDeveloper
V i currently does not provide a way to use a text resource from a resource bundle file, so you
can just enter the text directly.
a. Open the CheckoutFlow task flow.
b. In the Structure pane, expand the view CheckoutShipping node.
c. Right-click the Train Stop and select Insert inside train-stop > Display Name from
context.

d. In the Property Inspector, set the display-name to Shipping.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 23
e. Similarly, set the display-name for CheckoutPayment to Billing and for
CheckoutConfirm to Confirmation.
12. Optional step: You may choose to skip this test in the interest of time without
affecting subsequent practices.
Test the train functionality. To see all the train stops, all the train stop view activities must
be associated with pages, so you have to create the other pages. However, because you
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

are going to delete them after testing the train, for now just create a temporary page for
each with only an output text item on it. Do not add any data binding. You can just create
the pages in the default directory to separate them from the more permanent pages that are
in your \oracle\storefront\ui\pages directory.
a. Double-click each view activity in turn (CheckoutPayment and CheckoutConfirm)
and click OK to accept the defaults in the Create JSF Page dialog box.
b. When the page opens in the designer, drag an Output Text to the page.
c. In the Property Inspector, change the Value of the Output Text item to reflect the title of u se
the page—Checkout Payment or Checkout Confirm. You do not need to place
e to
that text in the resource bundle because you do not use it on the permanent page that n s
i ce
el
you create later. You use this Output Text value only to be able to determine which
page appears at run time for the next step.
a b l
d. Run the CheckoutShipping page from the task flow to see the results. The navigation fe r
n s
train and button bar appear, with labels for each train stop. You can use either the
a
- tr
Billing link or the Next button to navigate to the payment page.
n
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d However, because you have added the train component and train button bar to only the
V i first page, you cannot navigate to the other pages from the payment page. You take
care of that problem when you create the real pages.
e. When finished, close the browser and undeploy the application as described in step
6(i) of Practice 2-4.
f. Delete the two temporary pages:
1) In the CheckoutFlow task flow, select the CheckoutPayment and
CheckoutConfirm view activities and delete the value in their page property.
2) In the Application Navigator, multiselect the CheckoutConfirm and
CheckoutPayment pages. Right-click and select Delete.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 24
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 25
Practice 14-5: Simplifying and Enhancing a Task Flow
When defining navigation and task flows, you may have noticed that the ShoppingFlow has
several control flows with the same name whose target is the same activity. For example, there
are two control flows named detail that have a target of ProductDetails. In this practice,
you simplify the shopping task flow by defining a global control flow rule, and you also add calls
to other task flows.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Simplify the ShoppingFlow task flow by defining a global rule.


a. Open the ShoppingFlow task flow.
b. Drag a Wildcard Control Flow Rule from the Component Palette to the task flow.
c. Select one of the search control flow cases and in the Property Palette, change its
From Activity Id to the wildcard rule by selecting it from the drop-down list.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
d. Delete the other search control flow rule.a nodiagram
The e ฺ should now look similar to the
following screenshot: a s
h t Gu i d
)
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

e. Select one of the detail control flow rules and in the Property Palette, change its
from-activity-id to the wildcard rule by selecting it from the drop-down list.
f. Delete the other detail control flow rule. The diagram should now look similar to the
following screenshot:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 26
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

g. Select the shop control flow rule and in the Property Palette, change its from-activity-
id to the wildcard rule by selecting it from the drop-down list.
u se
h. Rearrange the items on the diagram to look similar to the following screenshot:
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
a toSthe ShoppingFlow:
mactivities
2. Add three task flow call
• @ g
To call theocheckout this
flow
• ฺ vin the shopping cart
Tocdisplay
C

(a
To add an item to the cart
d A a. From the Application Navigator, drag CheckoutFlow to the ShoppingFlow task flow
Vi no diagram in the editor to create a task flow call activity.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 27
b. Drag a Control Flow Case from the wildcard to CheckoutFlow and name the
outcome checkout.
c. From the Application Navigator, drag the ShoppingCartFlow to the ShoppingFlow
task flow diagram in the editor to create a task flow call activity.
d. In the Property Inspector, change the Activity ID of the task flow call activity to
AddShoppingCart. Do not change the ID in the Task Flow Reference section.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
e. i
Drag a Control Flow Case from the wildcard to AddShoppingCart and lname ce the
outcome add.
r a ble
n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
i n
f. (a cฺv
From the Application Navigator, again drag ShoppingCartFlow to the ShoppingFlow
A C task flow diagram in the editor to create a task flow call activity.
d
V ino g. In the Property Inspector, change the Activity ID of the task flow call activity to
DisplayShoppingCart. Do not change the ID in the Task Flow Reference section.
h. Drag a Control Flow Case from the wildcard to DisplayShoppingCart and name the
outcome cart.

You later add logic to the application so that there is a difference between displaying
the cart and adding an item to the cart.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 28
i. Open the ProductCatalog page and to the right of the Search button, add a button.
1) Using the resource bundle, set the text property to Show Cart.
2) Set the action to cart to navigate to the DisplayShoppingCart activity.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m
3) Test the navigation with the
o
)Show Cart
e n tG button by running the ProductCatalog
ฺ c
page from the ShoppingFlow d
task flow.
m ail Stu
@ g this
ฺ v ino
C (ac
d A
n o
Vi 4) The Cart content should display now:

5) When you have finished, close the browser and undeploy the application as
described in step 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 29
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 14


Chapter 14 - Page 30
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 15
- r
on ฺ
Chaptern15
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 2
Practices for Lesson 15: Achieving the Required Layout
Practices Overview
In the practices so far, you have chosen the default layout for all the components that you have
used. That is a quick way to check whether your application is working and that data and flow
are handled correctly. This has resulted in pages that are functional, but not very visually
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

appealing. In this set of practices, you use layout components and techniques to enhance the
appearance of the application, and you implement partial page rendering to coordinate products
with a selected subcategory.
If you successfully completed all sections of the previous practice, including the optional steps,
you can continue working in the same project. However, if you prefer to start with a clean
application that contains everything completed up to the start of this lesson, open
Storefront-15.jws and edit the database information as described in step 4 of Practice 2-4.
This practice contains some optional steps that are similar to steps already done. If you want to u se
build the entire application yourself, you can complete the optional steps. However, in the
e to
interest of time, you may want to skip them. If you do so, you must begin the practices for the n s
next lesson by opening the starter application for that lesson. i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 3
Practice 15-1: Stretching Tables and Columns
To enhance the appearance of tables in the application, it is a good practice to stretch them so
that they occupy the entire browser space. Tables and other components are automatically
stretched if they are contained in a stretched component that automatically stretches its children
(Panel Splitter, Panel Stretch, or Decorative Box layout components). Even so, there is no harm
in stretching the table itself to avoid display problems no matter which type of layout component
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

contains the table.


In this practice, you stretch all tables and the last column of each table.
1. Stretch the last columns of the following tables, and stretch the tables themselves:
Page Table
ProductCatalog masterDetail1 table

se
ProductCatalog Subcategories table
ProductCatalog Products table
to u
ProductSearch (optional) Search results table n s e
i ce
ShoppingCart (optional) Items table
b l el
BrowseSuppliers (optional) Suppliers table
f er a
n s
apage.
a. In the Application Navigator, select the ProductCatalog
- t r
b. In the Structure window or in the editor, select the
n onaf:table

– masterDetail1
component.
s a ide
c. a
h t Gu> Width to 100%. Tab out or click in any
In the Property Inspector, set the Appearance
)
other field to apply the new o m Youecan
c value. n see the effects of table stretching in the
i l ฺ
editor, as the table boundaries
a d
tu fill the horizontal space in the editor.
expand to
d. m
Select last fromgthe Column S
s Stretching drop-down list.
icolumn
You can see o @the effectst h
of stretching in the editor, as the last column expands
upin
to fillฺv the space.

C (ac
d A
n o
Vi

e. Apply the same type of stretching to the other two tables on the page: the one for
subcategories and the one for products. However, in the Products table (table2),
stretch the middle column (column3), because it is the one that contains a large
amount of text. To do so, follow these steps:
1) Select the middle column and give it the Id of Description.
2) Optional: (You may get errors when nondefault values of Id and TestId are not
identical. To avoid this possibility, reset the TestId to its default value.)
3) Select the table and set Column Stretching to column:Description.
f. Save your work.
g. Optional step: (If you choose not to complete this step, you must begin the
practices for the next lesson by opening the starter application.)
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 4
Similarly, stretch the table and the last column for all tables on the following pages:
ProductSearch (Search results table)
ShoppingCart (Items table)
BrowseSuppliers (Suppliers table)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 5
Practice 15-2: Adjusting JDeveloper’s Default Layout Components
When you created certain components on your pages, JDeveloper imposed some default
layout. In this practice, you modify some of these default layout components to enhance the
appearance of the pages.
1. Modify headings in the Panel Group Layout components on the ProductCatalog page.
Change the headings to Categories and Subcategories.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Open the ProductCatalog page.


b. In the Structure window, expand jsp:root > f:view > af:document > af:form >
af:panelGroupLayout.
c. When you dragged the Categories and Subcategories to your page as master table
and detail table, JDeveloper created these tables in af:panelHeader components with
default headings. Change these headings to Categories and Subcategories.
1) In the Structure window, select af:panelHeader – BrowseCategory1.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
(2)a
A C In the Property Inspector, change the Text property to Categories. Ensure that

Vi nod 3)
you use a resource bundle.
Similarly, set the Text property for the af:panelHeader – BrowseSubCategory1
to Subcategories.
2. On the ProductCatalog page, two of the tables and panel headers are grouped under an
af:panelGroupLayout component. Enable this component to display scroll bars when the
browser is too small to display all of its contents, and place the third table in the same panel
group layout.
a. In the Structure window, select af:panelGroupLayout.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 6
b. In the Property Inspector, select scroll from the Layout drop-down list.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Drag the Products table to the af:panelGroupLayout – scroll component. u se


e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
a i S
g
3. Optional step: (If you
mchoose i s
not to complete this step, you must begin the practices
for the nextn
t h
o@ by opening the starter application.)
lesson
v i
( acฺ open ProductSearch page and set the default Panel Group Layout component
Similarly,
to scroll.
d AC
Vi no

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 7
Practice 15-3: Adding Layout Components to Existing Pages
In this practice, you add layout to pages to enhance their appearance.
1. Add a Panel Header named Products to contain the Products table on the
ProductCatalog page.
a. Open the ProductCatalog page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the Structure window, expand jsp:root > f:view > af:document > af:form >
af:panelGroupLayout-scroll.
c. In the Structure window, right-click af:table and select Surround With.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
o deADF Faces > Panel Header and click OK.
d. In the Surround Witha ilฺc box,
dialog t u
select
g m foristheSpanel header, set the Text property to Products,
e. In the Property th bundle.
Inspector
@ a resource
ousing
i n
optionally
f. (a cฺvyour work.
Save
2.AC
On the ProductDetails page, place the Product form, which is contained by default in a
n o d panel form layout, into a panel header titled Product Detail. Add a toolbar for the existing
Vi buttons.
a. Open the ProductDetails page.
b. In the Structure window, expand jsp:root > f:view > af:document > af:form.
c. Right-click af:panelFormLayout and select Surround With.
d. In the Surround With dialog box, select ADF Faces > Panel Header and click OK.
e. In the Property Inspector for the panel header, set the Text property to Product
Detail, optionally using the resource bundle.
f. In the Structure window, expand af:panelHeader > Panel Header facets.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 8
g. Drag a Toolbar from the Component Palette to the toolbar facet of the panel header, in
either the Structure window or in the editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
h. Drag the existing Search and Shop buttons to the toolbar, in either the Structure n s
window or in the editor. i ce
b l el
fe ra
a n s
n - tr
i. Save your work. When you have finished,a
o ฺ look similar to this…
thenpage should
a s i d e
) h nt G u
m
co tude
i l ฺ
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi …and the Structure window should look similar to this:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 9
3. Optional step: (If you choose not to complete this step, you must begin the practices
for the next lesson by opening the starter application.)
Similarly, on the SupplierUpdate page, put the Supplier form that is contained in a panel
form layout into a panel header. You do not need to change the heading.
Hint: The SupplierUpdate page is in the supplier subdirectory of the
\oracle\storefront\ui\pages directory.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Surround the Panel Form Layout with a Panel Header, but do not change the Text
(heading).
b. Add a Toolbar component and move the existing buttons to the toolbar facet of the
panel header.
c. For now, do not change the text of the panel header, because later you add a
conditional text display.
d. Using the Style property group and the Box tab, set the Width of the panel header to
500 pixels.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
e. Save your work. When you o m
have
)finished,
e n ttheGpage should look like this…
a ilฺc Stud
g m is
o@ th
ฺv i n
C (ac
d A
n o
Vi
…and the Structure window should look like this:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 10
4. Optional step: (If you choose not to complete this step, you must begin the practices
for the next lesson by opening the starter application:)
Similarly, on the BrowseSuppliers page, put the Supplier table into a panel header with
the heading Select a Supplier for Update.
a. Surround the Supplier table with a Panel Header.
b. Using the resource bundle, change the Text to Select a Supplier for Update.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Save your work.


5. Optional step: (If you choose not to complete this step, you must begin the practices
for the next lesson by opening the starter application.)
Similarly, on the ShoppingCart page, put the table into a panel header labeled Shopping
Cart.
a. Surround the table with a Panel Header.
b. Use the resource bundle to change the Text to Shopping Cart.
u se
c. Add a Toolbar component and move the existing buttons to the toolbar facet of the
panel header. e to
n s
d. Save your work. i ce
6. Optional step: (If you choose not to complete this step, you must begin the practices b l el
for the next lesson by opening the starter application.)
fe ra
Similarly, on the CheckoutShipping page, put the panelFormLayout containing the
a n s
Shipping form into a panel header titled Shipping Address.
n - tr
no eฺ
a. Surround the Panel Form Layout with a Panel Header.
a
a s uid
b. Use the resource bundle to change the Text to Shipping Address.
h
c. m
Do not move the train or the train
o e t Ginto the panel form layout.
) buttonnbar
d.
a lฺc havetfinished,
Save your work. Wheniyou u d the Structure window should look like this:
g m is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 11
Practice 15-4: Creating New Pages with Required Layout
You have not yet created the last two pages in the CheckoutFlow train. In this practice, you
create those pages, starting with the layout components, and then adding databound
components.
1. Create the CheckoutPayment page. The page should contain a panel group layout with
two panel headers: one that displays the billing address and the other displaying payment
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

options. The final layout should be something like this:

u se
e to
n s
i ce
b l el
fe ra
a n s
a. Open the CheckoutFlow task flow.
n - tr
b.
a no eฺ
Double-click the CheckoutPayment view activity to create the page. Ensure that you

h a s uid
create it in the \oracle\storefront\ui\pages directory.

m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

c. Drag a Panel Group Layout from the Component Palette to the page and set its
Layout property to scroll.
d. Drag two Panel Headers to the page, one below the other and both within the panel
group layout. You may find it easier to drag the panel headers to the
af:panelGroupLayout in the Structure window.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 12
e. Set the Text of the top panel header to Billing Address and of the other to
Payment Options, optionally using a resource bundle.
2. Now that you have the layout defined, you can add databound components. First, you add
the billing address.
a. Drag the FODCheckoutAMDataControl > ShoppingCart1 > PaymentOption1 >
BillingAddress to the first panel header.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
@ th
ฺ v ino
b.( a c it as a
Create Form > ADF Form.
C
A Include the following attributes in order, deleting others:
c.
n o d
V i Address1
Address2
City
StateProvince
PostalCode
CountryId
d. Do not include Navigation Controls or a Submit Button.
e. Click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 13
f. Save your work. The page should now look like this:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
3. In a similar manner, add the payment options. i ce
a. Drag the FODCheckoutAMDataControl > ShoppingCart1 > PaymentOption1 data b l el
control to the second panel header on the page and add it as an ADF Form.
fe ra
b. Include the following attributes in order, deleting others: a n s
n - tr
no eฺ
PaymentTypeCode
CardTypeCode a
s uid
AccountNumber h a
) nt G
ExpireDate
o m
c tude
i l ฺ
ma is S
CheckDigits
g th
RoutingIdentifier
@
ฺ v ino
InstitutionName
c. Docnot include Navigation Controls or a Submit Button.
a
C
d.
(Click OK.
d A
i n o e. Save your work. Now the page should look like this:
V

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 14
f. Add some white space between the panels.
1) Drag a Spacer from the Component Palette to the Panel Group Layout facets >
separator—this provides a little white space between panels.
2) Save your work.
4. Create the CheckoutConfirm page, which has a more complicated layout than the other
pages because it is an overview of all of the order information. The layout should be like
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

this:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
o
a. In the CheckoutFlowatask t ude double-click the CheckoutConfirm view
ilฺcflowSdiagram,
mCheckoutConfirm
activity to creategthe
directory. o@ this page in the \oracle\storefront\ui\pages

ฺ inComponent Palette, drag a Panel Group Layout to the page and set its
vthe
b. c
From
(a
Layout property to scroll.
d AC
c. Drag a Panel Header to the Panel Group Layout and set its Text property to Payment
n o
Vi d.
Options, optionally using an existing text resource.
Drag a second Panel Group Layout to the first one, and set its Layout property to
horizontal and its StyleClass on the Style and Theme tab to AFStretchWidth.
e. Drag two Panel Headers to the horizontal Panel Group Layout. Set the Text of the first
to Shipping Address, and of the second to Billing Address, optionally using
existing text resources in the resource bundle.
f. Drag a spacer to the separator facets of each of the two Panel Group Layouts.
g. Drag another Panel Header to the outermost Panel Group Layout (the one with the
scroll layout) and set its Text to Order Items.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 15
The page should look like the following:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
5. Now that you have defined the layout, you can create databound components on the page.
b l el
Create a read-only table of shopping cart items on the Order Items panel header, and read-
fe ra
only forms for shipping address, billing address, and payment options on their respective
a n s
panel headers.
n - tr
a no eฺ
a. Drag the FODCheckoutAMDataControl > ShoppingCart1 > PaymentOption1 to the
Payment Options panel header as Form > ADF Read-only Form.
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d 1) Include the following attributes in order, deleting others:
V i Meaning
Meaning1
AccountNumber
ExpireDate
CheckDigits
RoutingIdentifier
InstitutionName
Note : Meaning and Meaning1 are the displayable values for PaymentTypeCode
and CardTypeCode, respectively. These attribute names are the default attribute
names for the view object. This is why it is important to take the time to relabel
them to something meaningful, as has been done in the LookupCodeEO entity
object control hints. You see the new labels at run time.
2) Do not include Navigation Controls or a Submit Button.
b. Drag the FODCheckoutAMDataControl > ShoppingCart1 > ShippingAddress to the
Shipping Address panel header as a Form > ADF Read-only Form.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 16
1) Include the following attributes in order, deleting others:
Address1
Address2
City
StateProvince
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

PostalCode
CountryId
2) Do not include Navigation Controls or a Submit Button.
c. Drag the FODCheckoutAMDataControl > ShoppingCart1 > PaymentOption1 >
BillingAddress to the Billing Address panel header as a Form > ADF Read-only
Form.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
o m e t G order:
) in thensame
1) Include the following attributes
Address1
Address2 ma
ilฺc Stud
City @
g this
ฺ v ino
StateProvince

C (ac PostalCode
d A CountryId
n o
Vi d.
2) Do not include Navigation Controls or a Submit Button.
Drag FODCheckoutAMDataControl > ShoppingCart1 > ShoppingCartItem1 to the
Order Items panel header on the page as a Table > ADF Read-only Table.
1) Enable Sorting.
2) Include the following attributes in order:
ProductName
Quantity
UnitPrice
LineTotal
3) Set the Width of the table to 100% and enable last column stretching.
e. Save your work. The page should look like this…

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 17
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
hasliket this:
…and the Structure window should) look G u id
o m e n
a ilฺc Stud
g m is
o@ th
v i n
( acฺ
AC
d
V ino

6. Optional Step: To test your checkout pages, you must add the same train components to
the second and third train stops. In the lesson titled “Ensuring Reusability,” you define a
page template to use for all these pages, and the train components are on it rather than on
the individual pages. However, for now you temporarily add them to each page for testing.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 18
Copy the train and train button bar from the CheckoutShipping page to each of the other
two pages in the CheckoutFlow.
a. Open the CheckoutShipping page.
b. In the Structure window, expand jsp:root > f:view > af:document > af:form.
c. Multiselect af:train and af:trainButtonBar.
d. Right-click and select Copy.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
e. Open the CheckoutPayment page.
n - tr
f.
g. Right-click af:form and select Paste.a no eฺ
In the Structure window, expand jsp:root > f:view > af:document > af:form.

h a s uid
h.
m ) nt G
Drag af:train and af:trainButtonBar above the af:panelGroupLayout.

l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

i. Perform steps f through h on the CheckoutConfirm page.


j. Run the CheckoutFlow to test the pages.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 19
Practice 15-5: Setting Conditional Display
Sometimes there is a need to display or not display attributes depending on specific conditions.
In our example, if the user selects a Credit Card payment type, you do not want to display the
RoutingIdentifier or the InstitutionName because those are used only for checks. If the user
selects a Direct Debit payment type, you do not want to display CardTypeCode or
ExpirationDate, because those are used only for credit cards.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

In this practice, you work on the CheckoutPayment page to set the attributes to be visible only
when they are needed, based on the Payment Type. You add Expression Language to the
components that you want to conditionally display, and you use partial page rendering to refresh
only those components, rather than the entire page.
The Payment Type codes are listed below.
CC Credit Card
DD Direct Debit
IN Invoice u se
e to
PP PayPal
n s
l i
1. The PaymentTypeCode is a choice list and its default binding gives you the positionce of the
selected value in the list, not the value. On the CheckoutPayment page,
a le an attribute
bcreate
value named PaymentTypeCodeValue for the value of the payment r
fe type code.
n s
a. Click the Bindings tab on the CheckoutPayment.jspx
n - tra page.
b. In the Bindings section, click Add .
a no eฺ
c. Select Generic Bindings > attributeValues.
h a s uid
d. Click OK.
m ) nt G

e. In the Create Attribute lBindingo
c tdialog d ebox:
i u
g ma is S
1) Select FODCheckoutAMDataControl.PaymentOption1 as the Data Source and
@
PaymentTypeCode
oOK. t has the Attribute.
v i n
2) ฺClick
( ac
C
n o dA
V i

f. In the Property Inspector, change the Id of the binding to PaymentTypeCodeValue.


(Click PaymentTypeCode1 in the Structure window if you do not see the ID in the
Property Inspector.)
Now you have a reference to the actual value of the PaymentTypeCode so that you
can use a condition based on its value. Save your work.
1) Because you are going to use partial page rendering for this action, you must reference the
component that triggers the partial page rendering. Set an Id and implement PPR on the
triggering component.
a. Click the Design tab on the CheckoutPayment.jspx page to go back to the design
view of the page.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 20
b. Select af:selectOneChoice for PaymentTypeCode in either the visual editor or the
Structure window.
c. Set the Id property to PaymentType.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

d. Set the Behavior > AutoSubmit property to true.


u se
3. The first attribute to set a condition on is CardTypeCode. If the payment type code is notto
CC (for Credit Card), then do not display this field.
n s e
a. Select af:selectOneChoice for CardTypeCode attribute in either the lvisual i ce editor
or the Structure window.
r a ble
b. Set the Visible attribute (in the Advanced panel) to:
n s fe
#{bindings.PaymentTypeCodeValue.inputValue
n - tra eq 'CC'}
If this expression evaluates to true, the attribute
n o is visible

in the UI.
Note: You can use the Expression Builder s ato helpidbuild
e the expression. To get to
Expression Builder, click the arrow a
) hiconnand
to the
G u
right of the Visible property on the
Advanced tab of the Property m
Inspector t select Expression Builder.
i l ฺ co tude
g ma is S
o@ th
v i n
( acฺ
d AC
Vi no
In the list at the left of the Expression Builder, select ADF Bindings > bindings >
PaymentTypeCodeValue > inputValue, which inserts
#{bindings.PaymentTypeCodeValue.inputValue} into the expression. You
then can add the condition to the end of the expression and click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 21
Note: Be sure to select the PaymentTypeCodeValue attribute binding and not the
PaymentTypeCode binding.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
c. a no eฺ which is the ID of the
Now set the PartialTriggers property to PaymentType,
triggering component. h a s uid
1) On the Behavior panel,oclick m e n tG
) the small down arrow next to the PartialTriggers
ฺ c tud
text box and selectilEdit.
g ma dialog
2) In the Edit Property i s Sbox, select selectOneChoice – PaymentType and
shuttle t h
oit@to the Selected list. (This means that when the PaymentType component
i n
ฺv an autosubmit, it refreshes this data control. When it does, the code in the
forces
a c
( Visible property executes. If the code evaluates to true, the data control
A C appears.)
n o d
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 22
3) Click OK.
4. Now set ExpireDate to be visible only if the Payment Type Code Value is CC. Define the
Visible and PartialTriggers properties.
a. Select af:inputDate for the ExpireDate attribute in either the visual editor or the
Structure window.
b. Set the Visible attribute (in the Advanced panel) to:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

#{bindings.PaymentTypeCodeValue.inputValue eq 'CC'}
If this expression evaluates to true, the attribute is visible in the UI.
Note: You can use the Expression Builder to help build the expression. To get to
Expression Builder, click the arrow icon to the right of the Visible property on the
Advanced tab of the Property Inspector and select Expression Builder.
In the list at the left of the Expression Builder, select ADF Bindings > bindings >
PaymentTypeCodeValue > inputValue, which inserts
#{bindings.PaymentTypeCodeValue.inputValue} into the expression. You u se
then can add the condition to the end of the expression and click OK. e to
n s
Note : Ensure that you select the PaymentTypeCodeValue attribute binding and not
i ce
the PaymentTypeCode binding.
b l el
c. Now set the PartialTriggers property to PaymentType, which is the ID of the
fe ra
triggering component.
a n s
- tr
1) On the Behavior panel, click the small down arrow next to the PartialTriggers
n
text box and select Edit.
a no eฺ
h a s uid
2) In the Edit Property dialog box, select selectOneChoice – PaymentType and
) nt G
shuttle it to the Selected list.
m
o
c tude
5. In the same way, set CheckDigits to be visible only if the value is CC.
l ฺ
a. Select af:inputText
i
a for CheckDigits
S attribute in either the visual editor or the
g m i s
Structure window.
o @ th
b. Repeat i n
v steps (4b)–(4c) and code are similar.
acฺ
6. Set(RoutingIdentifier and InstitutionName to be visible only if the value is DD.
C
A Hint: Remember to set the expression for the Visible property and select PaymentType for
n o d the PartialTriggers property for these attributes.
Vi 7. Run CheckoutShipping from the CheckoutFlow task flow and navigate to the
CheckoutPayment page to test your work.
a. Test changing the Payment Type value to see the results. You should see that different
attributes appear depending on the value that you set.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 23
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 24
Practice 15-6: Implement PPR to Coordinate Products Display with
Selected Subcategory
When you added the Products table to the ProductCatalog page, you added it as an
independent table, not as a master-detail table. It is not set to be refreshed when the selection
in the SubCategory table changes. In this practice, you use partial page rendering (PPR) to
refresh the Products table. (This PPR is defined automatically when you add components as
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

master-detail.)
1. Set the SubCategory table to be the triggering component for PPR.
a. Open the ProductCatalog page and select the af:table within the subcategories
panelHeader.
b. Set Id to SubCategory.
c. Verify that Row Selection is selected for this table. Use the table Edit icon in the
Property Inspector. (Do not just change the Row Selection property in the property
u se
inspector.)
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
2. Set the Products table to be the PPR target that is refreshed when the selected
subcategory changes.
a. Select the Products table (table2).
b. In the Property Inspector, select Edit to set the Partial Triggers property to
SubCategory.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 25
c. In the Edit Property dialog box, shuttle SubCategory in the Selected pane.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
d. Click OK.
n - tr
3. Test the page.
a no eฺ
a. Run the page, either directly or from a
h stask flow.
the
u id
b. Select Category, then SubCategory
m ) andntcheckG that the correct products appear.
o e
6(i)a
described in step m
i c Syour
c. When you have finished,lฺclose
of Practice
udbrowser and undeploy the application as
t2-4.
@ g this
ฺ v ino
( ac
C
n o dA
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 15


Chapter 15 - Page 26
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 16
- r
on ฺ
Chaptern16
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 2
Practices for Lesson 16: Ensuring Reusability
Practices Overview
In this set of practices, you begin to implement reusability in the application.
When several pages are used in succession, it is a good practice to make sure that the layout of
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

each page is exactly the same. For example, you want navigation buttons to appear in exactly
the same location on pages that are used in series, such as CheckoutFlow. To make the layout
cleaner and reusable, you create and apply a template to the pages.
The FODShoppingDashboard page is meant to be the main page of the application. Other
applications that will be developed for this company should use a similar look, so you create a
page template that imposes a certain layout. You then create the FODShoppingDashboard
page, using this page template.
The bounded task flows that you have created so far have used pages, not page fragments.
This enabled you to test them independently. However, now you incorporate these task flows as u se
regions on the main FODShoppingDashboard page. To do so, you must first convert the
e to
bounded task flows to use page fragments. n s
i ce
If you successfully completed all sections of the previous practice, including the optional steps,
you can continue working in the same project. However, if you prefer to start with a clean b l el
application that contains everything completed up to the start of this lesson, open fe ra
a
Storefront-16.jws and edit the database information as described in step 4 of Practice 2-4. n s
n - tr
This practice contains some optional steps that are similar to steps already done. If you want to
a no eฺ
build the entire application yourself, you can complete the optional steps. However, in the
a s uid
interest of time, you may want to skip them. If you do so, you must begin the practices for the
h
) nt G
next lesson by opening the starter application for that lesson.
m
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 3
Practice 16-1: Converting Bounded Task Flows to Use Page
Fragments
In this practice, you convert all of your bounded task flows to use page fragments rather than
pages. After you have done this, you no longer can run the task flows independently. You would
need to either call them from an unbounded task flow or use them as regions on a page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Convert CheckoutFlow to use page fragments.


a. Open the CheckoutFlow task flow in the editor.
b. Right-click the diagram and select Convert To Task Flow With Page Fragments.
c. In the Convert To Task Flow With Page Fragments dialog box, click OK. You do not
need to keep a copy of any of the pages.
d. In the warning dialog box, click Yes to continue. You should see that the
use-page-fragments property of the task flow is now set to true.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
You should also see that the .jspx h a
files
sfor the ucheckout
id pages have been converted to
m ) nt G
.jsff files.
l ฺ o
c tude
i
g ma is S
o@ th
v i n
( acฺ
AC
d
V ino

e. Select one of the .jsff files in the Application Navigator.


f. Observe in the Structure window that the files no longer contain the f:view,
af:document, and af:messages tags.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 4
2. So that you can use all bounded task flows as regions on a main page, repeat the above
steps to convert all the bounded task flows to use page fragments,
ManageSupplierFlow, ShoppingCartFlow, ShoppingFlow, and
ShowSuppliersFlow. Note that all.jspx files (except for ProductCategory.jspx)
are now converted to .jsff (page fragment) files.
Save your work.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

3. There is only one full page left, which is ProductCategory.jspx. This is a page on the
unbounded task flow. Extract this page into its own bounded task flow named
ProductCategoryFlow, and then convert it to use page fragments as well.

u se
e to
n s
i ce
b l el
a. Open adfc-config.xml. Make sure that the views appear in the diagram. fe ra
b. a n
Right-click the ProductCategory view activity and select Extract Task Flow. Click
s
Yes in the Warning dialog box. n - tr
c. no eฺ
In the Extract Bounded Task Flow dialog box:
a
a s uid
1) Enter ProductCategoryFlow as the File Name.
h
m ) nt G
2) Append \oracle\storefront\ui\flow to the Directory path.
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

3) Click OK.
d. The task flow opens in the editor. Right-click the ProductCategory view activity and
mark it as the default activity.

e. Convert ProductCategoryFlow to use page fragments as you did the other task flows.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 5
f. When you extract a task flow, JDeveloper creates a task flow call on the original task
flow. Delete the task flow call activity from adfc-config.xml.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
g. Save your work. n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 6
Practice 16-2: Creating a Page Template and Applying It to Existing
Pages
In this practice, you create a page template and apply it to the pages in CheckoutFlow. You
previously added the train components and arranged them on each of the checkout pages. This
duplication of effort is not that bad if there are only a few pages. However, if there are many
pages, this duplication becomes a little tedious and possibly error-prone.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

To avoid this unnecessary duplication, you now create a template that manages the train
components for each of the pages. The template also contains a Panel Group Layout and a
Panel Header to provide additional layout structure for the checkout pages.
1. Create a new page template named CheckoutPageTemplate, with a content facet and
a required title attribute.
a. In the Application Navigator, right-click the directory where you have been filing pages
and select New.
b. In the New Gallery, select Web Tier > JSF > JSF Page Template. u se
e to
c. Set the following properties for the new page template:
n s
i ce
File Name: CheckoutPageTemplate.jspx
b l el
Directory: <ProjHome>\public_html\oracle\storefront\ui\
fe ra
pages\templates
a n s
Page Template Name: n - tr
no eฺ
CheckoutPageTemplate
a
sicon touadd
id the facet.)
Facet Definitions tab a
(Click thehAdd
Name:
o m )content
e n tG
a ilฺc Stud
g m is
o@ th
v i n
( acฺ
d AC
i n o d. Click the Attributes tab to specify the following:
V
Attributes tab (Click the Add icon to add the attribute.)
title java.lang.String required

e. Click OK.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 7
2. To the page template, add the layout and train components that you want to use on all the
checkout pages.
a. Add a Panel Group Layout on af:pageTemplateDef.
1) Set its Layout property to scroll.
2) If necessary, drag the panel group layout above af:xmlContent in the Structure
window.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Drag a Train to af:panelGroupLayout.


c. Set the Value property of af:train to u se
e to
#{controllerContext.currentViewPort.taskFlowContext.trainModel}.
n s
(You can use Expression Builder and select ADF Controller Objects >
i ce
controllerContext > currentViewPort > taskFlowContext > trainModel to insert into
b l el
the expression.)
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
d. Drop a Panel Header on the af:panelGroupLayout and set its Text to
#{attrs.title}.
(You can use Expression Builder and select JSP Objects > attrs > title to insert into
the expression, and then delete the original value.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 8
e. Add a Facet Reference named content to the template.
1) Drag Facet Ref to af:panelHeader.
2) Set FacetName to content.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

f. Expand the af:panelHeader > Panel Header facets node in the Structure pane.
g. Add a Toolbar to af:panelHeader > Panel Header facets > toolbar.
h. Add a Button to af:toolbar.
1) Set the Text to Cancel, optionally using the resource bundle. u se
e to
2) Enter cancel for the Action property.
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
3) Set the Immediate property )to true. t G
m en
ctooaf:toolbar
i. Add a Train Button Bar
a i l ฺ t u d inside the af:panelHeader toolbar facet
property to S
and set the Valuem
@ g t h is
ino Button to af:toolbar inside the af:panelHeader toolbar facet.
#{controllerContext.currentViewPort.taskFlowContext.trainModel}.
j. v
Addฺanother

C (ac
d A
n o
Vi

1) Set Text to Submit.


2) Set Action to submit.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 9
3) Using the Expression Builder, set the Disabled property to
#{controllerContext.currentViewPort.taskFlowContext.trainMode
l.next ne null}.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Note: If you use the Expression Builder, it displays
s
athen code as if it were an error.
- t r
It has context for the trainModel, but does notnunderstand .next in the
expression. You can ignore the error. a n
o ฺ
a s i d ethe following…
3. Save your work. The page template should look
) h nt G u
similar to
m
co tude
i l ฺ
g ma is S
o@ th
v i n
( acฺ
AC
d
V ino …and the Structure window should look similar to the following:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 10
4. Apply the template to the checkout pages. (You cannot use the IDE to apply a template to
an existing page. However, you can add the template-related code to an existing page.)
a. Open CheckoutShipping.jsff.
b. Click the Source tab.
c. In the Structure window, select af:train and af:trainButtonBar. These components are
no longer needed in the page fragment because they are contained in the page
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

template.
d. Back in the Source editor, replace the highlighted code with the following: (You can
copy the code from PageTemplate.txt in your files directory.)
<af:pageTemplate
viewId="/oracle/storefront/ui/pages/templates/CheckoutPageTempla
te.jspx">

se
<f:facet name="content"/>
<f:attribute name="title"/>
to u
</af:pageTemplate>
n s e
i ce
The error will be solved in the following steps.
b l el
e. Click the Design tab. fe ra
f. Note that in the Structure window, there is now an af:pageTemplate, an a n s
n - tr
f:attribute, and a content facet. Set the Value property of f:attribute to
no eฺ
Shipping, optionally using the resource bundle.
a
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i 5. The template contains the outermost Panel Group Layout (which holds the train, buttons,
and the Panel Header). Therefore, when you apply the template to your page, you must
move the content to the template content facet.
a. Using the Structure window, drag af:panelHeader – Shipping Address to the
content facet.

6. Apply the template to the other pages in the checkout flow, using Billing as the title for the
CheckoutPayment page and Confirmation as the title for the CheckoutConfirm page.
a. Open CheckoutPayment.jsff.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 11
b. Repeat the steps above, changing the value of the title attribute to Billing. (The
content area of this page is in the panelGroupLayout.)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Open CheckoutConfirm.jsff.
d. Repeat the steps above, changing the value of the title attribute to Confirmation.
(The content area of this page is in the outermost panelGroupLayout.) u se
7. Save your work. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 12
Practice 16-3: Creating a Page Template and Applying It to a New
Page
Your company is planning several applications that should have a similar look. The main page
should have an image at the top left, with the company name next to it. The lower part of the
page should be divided into two panels. The main flow of the application is to appear in the right
panel, whereas the left panel should have tabs for accessing other functionality that may be
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

available.
In this practice, you create a page template to be used on the main page of any of the
company’s applications. You then create the FODShoppingDashboard page and base it on this
template. The layout of the template should be as follows:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
1.
c ฺ vin
In the templates subdirectory of your directory for pages, create a new page template
named MainPageTemplate. Define content areas named companyLogo, tab1Content,
( a
tab2Content, and mainContent. Define required attributes called companyName,
A C
tab1Title, and tab2Title.
n o d
V i a. In the Application Navigator, right-click the directory where you have already created a
page template and select New.
b. In the New Gallery, select Web Tier > JSF > JSF Page Template.
c. Set the following properties for the new page template, and then click OK:
File Name MainPageTemplate.jspx
Directory <ProjHome>\public_html\oracle\storefront\ui\p
ages\templates
Page Template Name MainPageTemplate
Facet Definitions tab companyLogo
(Click the Add icon to tab1Content
add each facet.) tab2Content
mainContent

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 13
Attributes tab (Click companyName java.lang.String required
the Add icon to add tab1Title java.lang.String required
each attribute.) tab2Title java.lang.String required
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2. The new template opens in the editor. Add a component with resizable vertical panes, so
that page developers can resize it to fit the size of the image that they add to the top pane.
u se
The component should be one that automatically stretches its children. Stretch it to fit the
e to
browser vertically and horizontally.
n s
i ce
el
a. Drag a Panel Splitter to the page. Ensure that it appears above af:xmlContent in the
Structure window.
a b l
1) Set its Orientation to vertical. fe r
a n s
2) Set its SplitterPosition to 125.
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
3.
a
You( want the company logo image and the company name to be arranged horizontally in
C
A the top portion of the page. Add a layout component to accomplish that, and add the
n o d
V i company logo and name.
a. In the Structure window, expand af:panelSplitter and Panel Splitter facets.
b. Drag a Panel Form Layout to the first facet and set the following properties:

1) Set Rows to 1 (so that the components you add are in one horizontal row).

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 14
2) Set Width to 500 pixels (so that the components you add are next to one
another, instead of spreading out to fit the browser width).
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Drag a Facet Ref to af:panelFormLayout and select companyLogo as the facet


name. This provides a spot for users of the page template to place an image.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
d. Drag a spacer to the af:panelFormLayout, a nothat etheฺ company name that you add in
so
the next step is not right up against the
h a slogo. uid
e. Drag an Output Text component
o m e tG
)to the naf:panelFormLayout.
a ilฺc Stud
1) Set its Value to #{attrs.companyName}. (You can use the Expression Builder
and select JSP
g m Objects
i s > attrs > companyName.) Designers of pages that use
o@
this template can t h
supply a value for the companyName attribute.
2) ฺIn i n
v the Style > Text section of the Property Inspector, set Color to Blue, Size to
C (ac xx-large, Italic to italic, and Bold to bold.
d A
n o
Vi

4. Below the header section that has the company logo and name, you want two resizable
panels that consume the remainder of the browser area. The left panel should contain two
tabs where page designers can place content, and the right panel should contain the main
content area. Add the layout and components for this area.
a. Drag a Panel Splitter to the second facet of the root af:panelSplitter and set its
Orientation property to horizontal.
b. Expand af:panelSplitter >Panel Splitter facets for the panel splitter that you just
added.
c. Drag a Panel Tabbed component to the first panel splitter facet.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 15
d. One detail item (corresponding to a tab) is created by default for the af:panelTabbed
component. Drag a second Show Detail Item to the af:panelTabbed component.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1) Set the Text of the first af:showDetailItem to #{attrs.tab1Title}. (You can


use Expression Builder.) This enables page designers to supply a label for the tab.
2) Set the Text of the second af:showDetailItem to #{attrs.tab2Title}.
e. Drag a Facet Ref to the first af:showDetailItem and select tab1Content as the facet
name.
u se
e to
n s
i ce
b l el
fe ra
a n s
f.
n - tr
Drag a Facet Ref to the second af:showDetailItem and select tab2Content as the

g.
facet name.
a no eฺ
Drag a Facet Ref to the second facet of the af:panelSplitter and select mainContent
h a s uid
as the facet name. This provides a spot for page designers to place the main content of
the application. m ) nt G
l ฺ o
c tude
h. i
Your template should look like the following:
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

i. Save your work. You must save a page template before you can use it.
5. On the main unbounded task flow for the application, create the FODShoppingDashboard
page, applying the template that you just created.
a. Open adfc-config.xml.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 16
b. Double-click the FODShoppingDashboard view activity to create the page, setting the
following properties:

File Name FODShoppingDashboard.jspx


Directory Add the following: \oracle\storefront\ui\pages
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Use Page MainPageTemplate


Template

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
a i S to customize the page for the Storefront application.
6. Use the attributes ofg mpage
the i s
template
Supply values t h
ofor@the attributes of the template. The company name should be Storefront
Demo c
i n
ฺvthe tabs should be labeled Categories and Suppliers. The IDE does not provide
(
a wayatoand
use a resource bundle, so you can enter hard-coded strings in this case.
C
A a. Set the attribute values in FODShoppingDashboard. In the editor, click the
n o d
Vi b.
FODShoppingDashboard tab, or reopen that file if you have closed it.
In the Structure window, select af:pageTemplate.
c. In the Property Inspector, set the following values:
companyName: Storefront Demo
tab1Title: Categories
tab2Title: Suppliers

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 17
The page should now look similar to the following:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
d. Add the company logo to the page.
b l el
1) In the page design, drag an Image component from the Component Palette to the
fe ra
companyLogo facet.
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
@ th
2)
ฺ inoInsert
In the
v
navigate to
Image dialog box, click the arrow next to Source, click Edit, and
the \images subdirectory of your Labs main directory.
(3) ac Select store.gif and click OK.
A C
n o d 4) In the Image Location Problem warning box, click Yes to copy the image into the
V i document root of your project.

5) In the Save Image dialog box, click Save.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 18
6)Back in the Insert Image dialog box, provide a ShortDesc if desired, and then click
OK. You should now see the image on the page.
e. Save your work.
7. Change the company name to display in red rather than in blue.
a. Open MainPageTemplate.jspx.
b. Expand af:pageTemplateDef > af:panelSplitter - vertical > Panel Splitter facets >
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

first > af:panelFormLayout - 1.


c. Select af:outputText - #{attrs.companyName}.
d. On the Style > Text section of the Property Inspector, set Color to Red.
e. Save your work. You must save the changes to a page template for them to be picked
up by pages that use the template.
f. Open FODShoppingDashboard. If it is already open, click its tab and select View >
Refresh. You should see that the Storefront Demo text is now red.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 19
Practice 16-4: Using Bounded Task Flows as a Region on a Page
In this practice, you create regions on the FODShoppingDashboard page by dragging bounded
task flows to the page as regions.
1. Add content to the Categories tab of the FODShoppingDashboard page. You should
display the ProductCategoryFlow in this area.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Select the FODShoppingDashboard page in the editor, and then in the Structure
window, click Freeze View .
b. From the Application Navigator, drag ProductCategoryFlow to the tab1Content facet
in the Structure window.
c. Create the flow as a Region.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i 2. Add the tab2 content. You should display the ShowSuppliersFlow in this area.
a. From the Application Navigator, drag ShowSuppliersFlow to the tab2Content facet in
the editor.
b. Create the flow as a Region.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 20
3. Add the main content. You should display the ShoppingFlow in this area.
a. From the Application Navigator, drag ShoppingFlow to the mainContent facet.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Create the flow as a Region.


c. Now unpin the Structure window by clicking Freeze View again.
4. Test the page by running it from the task flow. Make note of any errors and problems that
you encounter.
a. Right-click the FODShoppingDashboard view activity in the adfc-config.xml task u se
flow and select Run. The page in the browser should look similar to the following: e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
C
A b. Click the Suppliers tab. Click one of the links. You can see that the update supplier
n o d
V i page appears and displays the selected record, but with no way to navigate back to the
browse page (you fix this later).
c. In the main shopping region, note that you must scroll down to see the other tables on
the page (you fix this shortly). Select a new subcategory and verify that the correct
products appear in the Products table.
d. Click Show Cart to verify that the cart is displayed correctly.
e. Click Shop to return to the main shopping region.
f. Click Search. Enter a search criteria to verify that the search functionality works. Note
that there is no way to return to the main shopping page from this page. You soon fix
this problem.
g. Click the link on one of the products. The page should now show the product detail.
h. Click Shop to return to the main shopping page.
i. Click Show Cart again, and then click Checkout.
j. Verify that you can navigate through the checkout train, both by using the train and by
using the train buttons.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 21
k. Close the browser when you have finished, and undeploy the application as described
in step 6(i) of Practice 2-4.
5. Optional step: (If you choose not to complete this step, you must begin the practices
for the next lesson by opening the starter application.)
There is no way to return to the main shopping page from the ProductSearch page.
Implement navigation on that page to return to the main shopping task flow. Also add some
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

layout to the page to improve its appearance: Change the heading of the table to Search
Products and place all components under a root panel header with scrollbars.
a. Open the ProductSearch page fragment.
b. In the existing af:panelHeader, use the resource bundle to change the text from
ProductEO to Search Products.
c. Move af:table to the af:panelHeader.

u se
e to
n s
i ce
b l el
fe ra
a n s
d. n - tr
Drag a toolbar to the toolbar facet of the panel header.
e. a no eฺ
Drag a toolbar button to the toolbar facet and set the following properties on the
button: h a s uid
o m
Text (use the resource bundle)
) Shop
e n tG
Action a ilฺc Stud shop
g m is
o@
The Structure th look like this:
window should
ฺv i n
C (ac
d A
n o
Vi

f. Run FODShoppingDashboard again from the unbounded task flow to ensure that the
Shop button on the Product Search page navigates back to the shopping flow (Product
Catalog page).

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 16


Chapter 16 - Page 22
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 17
- r
on ฺ
Chaptern17
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 2
Practices for Lesson 17: Passing Values Between UI Elements
Practices Overview
When you built the ProductCatalog page, you created three separate areas on the page to
display Categories, SubCategories, and Products. Now you modify the page to display
only one table at a time.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Initially the Categories table should appear. When the user clicks the name of a category, the
Subcategories table should display the subcategories for the category that the user clicked.
Then if the user clicks a subcategory, the Products table should display the products for that
subcategory.
You accomplish this by using parameters. In the practices for this lesson, you modify the
ProductCatalog page to display specific tables and data based on those parameters.
If you successfully completed all sections of the previous practice, including the optional steps,
you can continue working in the same project. However, if you prefer to start with a clean u se
application that contains everything completed up to the start of this lesson, open e to
n s
Storefront-17.jws and edit the database information as described in step 4 of Practice 2-4.
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 3
Practice 17-1: Conditional Rendering Based on Parameters
In this practice, you define parameters and set up the tables on the ProductCatalog page to
conditionally appear based on the parameter values.
1. You must change the tables on the ProductCatalog page to accept a parameter to set the
row, rather than relying on row concurrency (as is currently the case). First, disable row
selection for the tables.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Open the ProductCatalog page fragment.


b. Select the Categories table either in the Structure window or the visual editor (the
default ID of the table is masterDetail1).
c. In the Property Inspector, click Edit.

u se
d. Deselect Row Selection and click OK. e to
n s
Note: By using the editor, JDeveloper removes the Row Selection and whatever i ce
listeners were required. If you just remove the row selection manually in the Property
b l el
Inspector, the listeners still remain.
fe ra
e. Select the SubCategory table and remove Row Selection in the same way.
a n s
2. Now you add page parameters. n - tr
no eฺ
Set page parameters on the ProductCatalog page to accept parameters named
a
a s uid
param_CategoryId, param_SubCategoryId, param_CategoryName, and
h
param_SubCategoryName.
m ) nt G
l ฺ o
c tude
The page parameters should get their values from pageFlowScope variables named
i
ma is S
CategoryId, SubCategoryId, CategoryName, and SubCategoryName.
g
a. Open the Page
o th for the ProductCatalog page (right-click the page and
@ Definition
i n
selectvGo to Page Definition, or click the Bindings tab).

b. (Addc the following parameters to the page definition:
a
d AC
i n o
V

id Value
param_CategoryId #{pageFlowScope.CategoryId}
param_SubCategoryId #{pageFlowScope.SubCategoryId}
param_CategoryName #{pageFlowScope.CategoryName}
param_SubCategoryName #{pageFlowScope.SubCategoryName}

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 4
The Page Definition’s Parameters section should look like the following:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Leave the page definition file open for the next step.
3. There is a method named setCurrentCategory() in the FODProductAM application
module. This method takes two arguments: a category ID and a subcategory ID. It
reexecutes the BrowseCategory, BrowseSubcategory, and BrowseProduct view object
queries based on the values that are passed to it.
Edit the bindings for the ProductCatalog page so that this method is executed upon u se
loading the page. Pass to the method two of the parameters that you have just defined e to
above. n s
i ce
a. Still in the page definition of the ProductCatalog page, click the Bindings and
b l el
Executables tab, then in the Bindings section, click the Create Control Binding green
fe ra
plus sign and add a methodAction.
a n s
b. n - tr
In the Create Action Binding dialog box, select the FODProductAMDataControl Data
no eฺ
Collection, and then confirm that setCurrentCategory appears in the Operation
a
drop-down list.
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

c. In the Create Action Binding dialog box, in the Parameters section, set these values
for the following parameters:

Name Value
categoryId #{bindings.param_CategoryId}
subCategoryId #{bindings.param_SubCategoryId}
(You can use Expression Builder; the parameters are shown under ADF Bindings >
bindings.)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 5
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

The Parameters section of the Create Action Binding Editor should look like the
following:
u se
e to
n s
i ce
b l el
fe ra
Click OK.
a n s
d. Add an InvokeAction to the Executables.
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
e. Set the id to@ th
o invokeSetCurrentCategory and bind it to setCurrentCategory.
f. i n
v Refresh property to ifNeeded.
Set ฺthe
a c
(Make sure that invokeAction is the first executable in the list. This ensures that the
g.
C
dA method is executed first when the page is loaded. (If you must move it, drag it to the

V ino top of the list.)

h. Save your work, and leave the page definition file open for the next step.
4. You have defined parameters that take their values from pageFlowScope variables. But
how do those values get stored in the pageFlowScope variables? In this step, you store
these values.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 6
In the Category and Subcategory tables, convert the category name to a link that
stores the name and ID in pageFlowScope variables. Use a Set Action Listener
operation to store each variable value.
Hint: You must first add the category ID to the page bindings.
a. Add CategoryId to the page bindings for both BrowseCategory1 and
BrowseSubCategory1.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1) Still in the page definition file for ProductCatalog, edit the BrowseCategory1
binding and add CategoryId as a display attribute. Hint: Click the
BrowseCategory1 binding; click Edit; select the rule in the Tree Binding editor;
shuttle the CategoryId from Available to Display Attributes.

u se
The Tree Binding editor should look like the following:
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

2) Repeat this step for BrowseSubCategory1 because you are going to use the
CategoryId that is selected in the SubCategories table to set the
subcategory-related parameters.
b. On the ProductCatalog page, convert the CategoryName field in the Categories
table to be a link. When a user clicks the link, the page should use setActionListeners
to set the pageFlowScope parameters.
1) Click the Design tab and in the Structure window for the ProductCatalog page,
and expand af:table - masterDetail1.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 7
2) Expand the first af:column node, and then click af:outputText for
CategoryName and copy (Ctrl + C) the Value property (to keep its content before
losing it when converting the outputText to a Link).
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

3) Right-click af:outputText for CategoryName and select Convert To.


4) Select Link, and then click OK in the Confirm Convert dialog box.
5) Paste into the Text property the value you copied a moment ago. The value
should be #{row.CategoryName}.

u se
e to
n s
li ce
l e
b following
6) Insert two setActionListeners operations inside the Link with
e r athe
properties.
a n sf
From To
n - tr
#{row.CategoryId} a no eฺ
#{pageFlowScope.CategoryId}
s uid
#{row.CategoryName} ha#{pageFlowScope.CategoryName}
m
Note: You use the CategoryName
o
) nand
e t GSubCategoryName parameters when
you set breadcrumbs
a ilฺcin theSnext
t udsection.
c. Repeat the stepsg m is
for the SubCategory table. (Make sure to pay close attention to the
@ t h
i no
pageFlowScope
ฺ v
variable names in each setActionListener.)
1)c Expand af:table - SubCategory in the second panel header.
C (a
2) Expand the first af:column node and click af:outputText for CategoryName
d A and copy (Ctrl + C) the Value property.
n o
Vi 3) Right-click af:outputText for CategoryName and select Convert To.
4) Select Link, and then click OK in the Confirm Convert dialog box.
5) Paste into the Text property the value that you copied a moment ago. The value
should be #{row.CategoryName}.
6) Insert two setActionListeners inside the Link with the following properties.
From To
#{row.CategoryId} #{pageFlowScope.SubCategoryId}
#{row.CategoryName} #{pageFlowScope.SubCategoryName}
5. Modify the rendering of the tables so that only a single table appears at a time.
Hint: If both category and subcategory parameters are null, the Categories table
should appear (no links have been clicked to set the parameters). If only the
categoryId parameter is set, the Subcategories table should appear because the
user clicked a link on the Categories table to set the category ID. If both parameters
are set, the Products table should be displayed (both Category and Subcategory links
have been clicked, so both parameters have been set).
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 8
a. Select the first af:table (masterDetail1) and, using the Expression Builder, set the
Rendered property so that the table appears if the param_CategoryId and the
param_SubCategoryId are both null. (This means that there were no parameters
set). The EL code is:
#{bindings.param_CategoryId eq null and
bindings.param_SubCategoryId eq null}
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Select the second af:table (SubCategory) and set the Rendered property so that u se
the table appears if the CategoryId parameter is set but the SubCategoryId e to
parameter is null. (This means that the page set a category, but not a subcategory.) n s
i ce
The EL code is:
b l el
#{bindings.param_CategoryId ne null and
fe ra
bindings.param_SubCategoryId eq null}
a n s
c.
n - tr
Select the third af:table - table2 (Products) and set the Rendered property so

a no eฺ
that the table appears if there is a categoryId and a subCategoryId. (This means
that the page has set a Category and subcategory.) The EL code is:
h a s uid
) nt G
#{bindings.param_CategoryId ne null and
m
o
c tudepage so that all tables are under a single panel
bindings.param_SubCategoryId ne null}
l ฺ
i
6. Modify the layout of the ProductCatalog
g ma depending
header whose title changes i s S on the table that appears.
t h
o@ window for the ProductCatalog page, select af:table –
a. In the Structure
ฺv i n in the second af:panelHeader and drag it to the first
( a c
SubCategory

A C af:panelHeader (the one currently labeled Categories).


Vi nod

b. Drag af:table from the third af:panelHeader to the first af:panelHeader.


c. Delete the second and third panel headers.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 9
d. Select af:panelHeader and in the Text property, replace the existing text with:
#{bindings.param_CategoryId eq null ||
bindings.param_SubCategoryId eq null ?
storefrontuiBundle.CATEGORIES : storefrontuiBundle.PRODUCTS}
e. Move the command buttons on the page to a toolbar in the toolbar facet of the panel
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

header.
1) Expand Panel Header facets.
2) Drag a toolbar to the toolbar facet.
3) Drag the Search and Show Cart buttons to the toolbar.
4) The Structure should now look something like:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
C
7.A Test the page.
n o d
Vi a.
b.
Run FODShoppingDashboard from the adfc-config task flow.
In the right pane, the page should initially display categories. Click one of the category
names.
c. The page should now display subcategories. (The title of the panel header still says
Categories.) Click one of the subcategory names.
d. The page should now display products, and the title of the panel header changes to
Products. Note that there is no way to navigate back to the Categories table. You
fix this in the next practice.
e. Close the browser when finished, and undeploy the application as described in step
6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 10
Practice 17-2: Using Parameters for Dynamic Breadcrumbs
When users click through links in the tables to display either the Subcategories or Products
table, they need a way to navigate back through the chain of tables. This is what the
breadcrumbs on the page enable them to do.
When users click the first breadcrumb, they should return to the top level of the breadcrumb list
to display the Categories table. You have already set the page to use the pageFlowScope
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

parameters to display the correct section of the page, so in this practice, you just set those
parameters based on which breadcrumb is clicked.
1. For the first breadcrumb, you want the Categories table to appear; therefore, reset all the
parameters to null.
Hint: Remember that the parameters get their values from the pageFlowScope variables.
a. On the ProductCatalog page, select the first af:commandNavigationItem—the one
labeled Store.
u se
b. Add four setActionListeners operations with the following properties:
e to
From To n s
i ce
#{null} #{pageFlowScope.CategoryId}
b l el
#{null} #{pageFlowScope.CategoryName}
fe ra
#{null} #{pageFlowScope.SubCategoryId}
a n s
n - tr
nyouo could
#{null} #{pageFlowScope.SubCategoryName}

a s a
Hint: After you add the first setActionListener,
i d eฺ use the Source tab to copy,
paste, and then modify the code.
) h t Gu
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
(ac
d AC
Vi no 2. Set the second breadcrumb to appear only if the user has clicked a category name in the
Categories table. Label the breadcrumb with the Category name that the user clicked in the
Categories table. Set the second breadcrumb to display the Subcategory table when
a user clicks it.
a. Select the second of the three navigation items in the Structure window.
b. Set the Text property to #{bindings.param_CategoryName}. You can use
Expression Builder to set this (ADF Bindings > bindings > param_CategoryName).
c. Set the Rendered property to
#{bindings.param_CategoryId ne null}.
d. If a user clicks the second breadcrumb, he or she wants to see SubCategories. You
use the setActionListeners to reset just the SubCategory parameters.
Add two setActionListeners with the following properties:
From To
#{null} #{pageFlowScope.SubCategoryId}
#{null} #{pageFlowScope.SubCategoryName}

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 11
3. Set the third breadcrumb to appear only if the user has clicked a category name in the
SubCategories table. Label the breadcrumb with the Category name that the user clicked
in the SubCategories table. Set the third breadcrumb to display the Products table
when a user clicks it.
a. Select the last of the three navigation items in the Structure window.
b. Set the Text property to #{bindings.param_SubCategoryName}.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Set the Rendered property to:


#{bindings.param_CategoryId ne null and
bindings.param_SubCategoryId ne null}
d. The Structure should look like the following:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

4. Test the page.


a. Run FODShoppingDashboard from the adfc-config task flow and use the table links
and the breadcrumbs to navigate around the shopping region.
b. Close the browser when you have finished and undeploy the application as described
in step 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 12
Practice 17-3: Implementing the Add to Cart Functionality
In this practice, you add a router and a method call to the shopping cart flow so that it can be
used either to display the cart or to add items to it. The calling page, ProductDetails, in the
shopping flow sets some parameter values that it passes to the shopping cart flow.
1. Modify the shopping cart flow to accept the following two input parameters:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Name Value Required


Action #{pageFlowScope.Action} True
ProductId #{pageFlowScope.ProductId} False
a. Open ShoppingCartFlow.
b. Click the Overview tab in the Editor window.
c. Click the Parameters tab.
d. Click the Add icon to add the two parameters shown above.
u se
e to
n s
i ce
b l el
fe ra
a n s
2. n - tr
Add a method call to the shopping cart flow that calls the addItemToCart() method of
a no eฺ
FODShoppingCartAM. Set the value of its productId argument to
a s uid
#{pageFlowScope.ProductId}. Navigate to the ShoppingCart view when finished.
h
a. m
In the Data Controls panel, expand
o e n tG
) FODShoppingCartAMDataControl.
b. ilฺc Stotuthe
Drag addItemToCart(Number)
a d shopping cart flow diagram.
g m is
o@ th
ฺv i n
C (ac
d A
n o
Vi

c. In the Edit Action Binding dialog box, set the Value of the productId parameter to
#{pageFlowScope.ProductId}, and then click OK.

d. Add a Control Flow Case from addItemToCart to ShoppingCart and label it done.
(You can later change this to include a commit function, but for now you simply want to
go to the cart after the method call.)
e. In the addItemToCart method call, change the fixed-outcome property to done.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 13
3. Add a router named ChooseAction as the default activity for the shopping cart flow. The
router should either display the shopping cart (display control flow case) or add an item
to it (add control flow case), depending on whether pageFlowScope.Action has a value
of Display or Add. The default action should be to display the cart.
a. Add a Router to the flow and name it ChooseAction.
b. Mark the ChooseAction router as the default activity for the page flow.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. Create two Control Flow Cases from ChooseAction: one to addItemToCart named
add, and the other to ShoppingCart named display.

u se
e to
n s
i ce
b l el
fe ra
a n s
d. - tr
Add two expressions to the ChooseAction router that evaluate
n
a no eฺ
pageFlowScope.Action. If the value is Add, use the add outcome. If it is Display,
use the display outcome. Hint: The add expression is:
h a s uid
#{pageFlowScope.Action == 'Add'}
m ) nt G
o
c tude
Note: The ChooseAction property is in the Cases section on the General tab of the
l ฺ
Property Inspector. i
e. g ma is S
Set the display outcome to be the default outcome of the router.
o @ th
c ฺ vin
( a
A C
n o d
V i

4. The shopping cart flow is expecting parameters named Action and optionally,
ProductId. Modify the shopping flow to send the correct parameters.
a. Open the ShoppingFlow diagram.
b. Select DisplayShoppingCart. Two parameters have been added to the
DisplayShoppingCart task flow call in the Parameters section of the Property
Inspector. Set a value for the Action parameter as follows:
Name Value

Action Display
ProductId Leave blank (or empty)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 14
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. In the ShoppingFlow, the same two parameters have been added to the
AddShoppingCart task flow call; select AddShoppingCart and in the parameters
section, set the values as follows:
Name Value
Action Add
u se
ProductId #{requestScope.ProductId}
e to
n s
The ShoppingFlow is now set up to send the Action parameter and, if needed,
l i ce to
send the ProductId as well.
r a ble
5. Finally, you must get the productId from the calling page and put itfe into the requestScope
variable ProductId. The call to add the item to the cart should a n s
be placed on the
ProductDetails page. Hint: There is currently no binding - t r
a. Open the ProductDetails page fragment. a n
on forฺ ProductId.
a s header’s e facet and label it Add Item
idtoolbar
b. Add a button to the toolbar of the h panel
) nt G u
to Cart. Set its Action to add.
o m
c tude
i l
c. Add a binding for ProductId. ฺ
g ma tab.is S
1) Click the Bindings
o @ th
i n
v the Bindings section, click Add .
2) ฺIn
a c
(3) Add an attributeValues binding whose Data Source is
A C FODProductAMDataControl.BrowseProduct and whose Attribute is
n o d
Vi
ProductId.

d. Return to the Design of the page and add a setActionListener to the Add Item to
Cart button and set the value of From to #{bindings.ProductId.inputValue}
and the value of To #{requestScope.ProductId}.
Hint: Right-click af:commandButton, select Insert inside > ADF Faces > Set
Action Listener and set the From and To values. Make sure to put the correct

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 15
values in the To and the From properties.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

6. Test by running FODShoppingDashboard from the adfc-config unbounded task flow.


Remember that the Add to Cart functionality is available from the Product Details page.
When you have finished, close the browser and undeploy the application as described in
step 6(i) of Practice 2-4.
Remark: If the Add Item to Cart button does not display the cart content, verify that in the
ShoppingFlow, when selecting the AddShoppingCart task flow call, the Input Parameters
are correctly set to the following values: u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 16
Practice 17-4: Implementing Create Supplier Functionality (Optional)
This practice is very similar to 17-3, and is, therefore, optional. If you choose not to complete
this practice, you must begin the practices for the next lesson by opening the starter application.
In this practice, you add a router to the ManageSupplierFlow task flow that decides whether the
UpdateSupplier page should display a supplier for update or should display a new record where
users can create a new supplier. You also add a method call to create a new record.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Modify the manage supplier flow to accept the following input parameter:
Name Value Required
SupplierAction #{pageFlowScope.SupplierAction} True
a. Open ManageSupplierFlow.
b. Click the task-flow-definition in the Structure window.
c. Select Parameters in the Property Inspector.
u se
d. Click Add to add the parameter shown above. e to
n s
i ce
b l el
fe ra
a n s
n - tr
2. Add a method call to the ManageSupplierFlow task
a noflow etoฺcall the CreateInsert operation
h a s uidactivity when finished.
for a new supplier and connect it to the SupplierUpdate
a. Open the ManageSupplierFlow)task flow.t G
m FODSupplierAMDataControl
coexpand e n
b. In the Data Controls panel,
a i l ฺ t u d > Supplier1 >

g m is S
Operations and drag the CreateInsert operation to the task flow diagram to create a
method call activity.
o@ th
c. Change
ฺ v i n
fixed-outcome of the CreateInsert method call activity to done.
d. (a c
Drag a Control Flow Case from CreateInsert to SupplierUpdate. from-outcome
C
A should default to done.
o d
n 3. Set up the task flow so that a new supplier is created when a parameter passed to it has a
Vi value of New, or that an existing supplier is updated when the parameter value is Update.
a. Add a Router to the flow and name it ChooseAction.
b. Right-click the ChooseAction router and mark the activity as the default activity for
the page flow.
c. Create two Control Flow Cases from ChooseAction: one to SupplierUpdate named
update, and the other to CreateInsert named new.
d. Add two expressions to the ChooseAction router that evaluate
pageFlowScope.SupplierAction. If the value is New, use the new outcome. If it is
Update, use the update outcome. Hint: The new expression is:
#{pageFlowScope.SupplierAction == 'New'}
Note: You define these expressions in the Cases section under the Common tab of
the Property Inspector.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 17
e. Set the update outcome to be the default outcome of the router.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

4. The manage suppliers flow is expecting a parameter named SupplierAction. Modify the
show suppliers flow to send the correct parameter.
a. Open the ShowSuppliersFlow diagram.
b. Add a parameter to the ManageSupplierFlow task flow call activity using the
Parameters section of the Property Inspector. (The parameter should be there by u se
default because you have set it on the ManageSupplierFlow task flow, so just set its e to
value in the task flow call activity.) n s
i ce
Name Value
b l el
fe ra
SupplierAction #{requestScope.SupplierAction}
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

5. Set the requestScope variable SupplierAction. The calls to create a new supplier or
update an existing one should be placed on the BrowseSuppliers page.
a. Open the BrowseSuppliers page.
b. Add a toolbar to the panel header’s toolbar facet.
c. Add a toolbar button to the toolbar and label it New Supplier. Set its Action to
update.
d. Add a setActionListener to the New Supplier button that sets the value of
#{requestScope.SupplierAction} to New when the button is clicked.
Set the From property to #{'New'} and the To property to
#{requestScope.SupplierAction}.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 18
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

e. Add a setActionListener to the SupplierId link.

u se
e to
f. Set the From property to #{'Update'}. Set the To value to n s
#{requestScope.SupplierAction} to Update when the link is clicked. li ce
b l e
f e a
6. Finally, change the panel header text of the SupplierUpdate page to rconditionally display
either Update Supplier or New Supplier, depending on the valuesof the parameter that is
passed.
- t r an
a. On the SupplierUpdate page, select the panel o
n n
header.
b. If you are not using resource bundle forstext, a changed ฺ Text to the expression
ethe
a
h t==G'New' i
u ? 'New Supplier' :
#{pageFlowScope.SupplierAction
'Update Supplier'} (alloon
)
mone line.)n
i l ฺ c d e
c. If you are using a resource
m a bundle S tufor text:
g
1) You must make some
@ s
thientries to the resource bundle: Although you can edit it
o
directly, it may be easier to change
in bundle (use UPDATE_SUPPLIER_TITLE the Display to Update Supplier, using the
ฺ v
( ac change it again to New Supplier, using the resourceasbundle
resource the key), and save it. Then
(use
A C NEW_SUPPLIER_TITLE as the key).
n o d
Vi 2) Now that you have the text resources entered in the resource bundle, you can use
them in a conditional expression to define the title based on the parameter. Enter
the following in the Text property (all on one line):
#{pageFlowScope.SupplierAction == 'New' ?
storefrontuiBundle.NEW_SUPPLIER_TITLE :
storefrontuiBundle.UPDATE_SUPPLIER_TITLE}

7. Test by running FODShoppingDashboard from the adfc-config unbounded task flow.


Remember that the New Supplier functionality is available from the BrowseSuppliers page.
There is not yet a way to commit updates or inserts; you add this in a later practice. When

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 19
you have finished, close the browser and undeploy the application as described in step 6(i)
of Practice 2-4.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 17


Chapter 17 - Page 20
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 18
- r
on ฺ
Chaptern18
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 2
Practices for Lesson 18: Responding to Application Events
Practices Overview
In the previous set of practices, you enabled a different table to appear based on parameters
that were set on the ProductCatalog page. You may wonder why you used page parameters
instead of using the pageFlowScope variables directly. This is because using parameters
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

enables your page to accept values from outside the task flow as well.
In addition to changing the display based on what the user clicks on the page, you also want to
change the display depending on what the user clicks in the category tree in the left region of
the containing page. When a user clicks a category in the tree, its subcategories should appear
in the shopping region. If the user clicks a subcategory in the tree, then the shopping region
should display its products.
You accomplish this by defining a contextual event that passes parameters from the
ProductCategory (tree) region to the ShoppingFlow region. First, you define the task flow u se
parameters on the ShoppingFlow, and then you enable the category tree to pass parameters
e to
(through the use of a bean) to the Shopping flow. You use a contextual event to coordinate this n s
interaction between the regions on the main page. i ce
If you successfully completed all sections of the previous practice, you can continue working in b l el
fe
the same project. However, if you prefer to start with a clean application that contains everything ra
completed up to the start of this lesson, open Storefront-18.jws and edit the database a n s
information as described in step 4 of Practice 2-4. n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 3
Practice 18-1: Defining Task Flow Parameters
The contextual event that you define in the practices for this lesson makes it possible for the
user to click a category in the ProductCategory region at the left of the page, and then display
the appropriate table in the ShoppingFlow region at the right of the page.
The ShoppingFlow region (ProductCatalog page) displays the appropriate table based on
pageFlowScope variables that you defined in the previous set of practices. To be able to set
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

pageFlowScope variables from outside the task flow, the task flow must be able to receive
values that are set in another region. In this practice, you define input parameters on the
ShoppingFlow task flow as the first step in setting up a contextual event.
1. Define four parameters on the ShoppingFlow task flow: CategoryId, CategoryName,
SubCategoryId, and SubCategoryName. Store them in pageFlowScope variables of
the same name.
a. Select the ShoppingFlow in the Application Navigator.
b. Select the task-flow-definition – ShoppingFlow node in the Structure window. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
c. no eฺto create the following input
Use the Parameters section of the Property Inspector
parameters: a
h a s uid
Name Value
m ) nt G
l ฺ o d e
c #{pageFlowScope.CategoryId}
CategoryId i t u
CategoryName g ma is#{pageFlowScope.CategoryName}
S
o@ t h
ฺ v i n
SubCategoryId #{pageFlowScope.SubCategoryId}
c
(aSubCategoryName #{pageFlowScope.SubCategoryName}

A C The Property Inspector should look like the following:

n o d
Vi

Note that this is just another way to set the pageFlowScope variables in the
ShoppingFlow task flow. The values are set either by clicking links on the
ProductCatalog page, as you defined in the previous set of practices, or they can be
set by receiving values via these input parameters on the task flow. After the values are
received, they have the same effect of setting the correct table to appear and setting
the breadcrumbs.
In the remaining practices in this lesson, you use a contextual event to pass values to
these parameters when a node in the category tree is clicked.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 4
Practice 18-2: Creating a Helper Method to Evaluate EL
Several methods that you use in this section must evaluate EL expressions. To avoid repeating
blocks of code, in this practice, you create a helper class with methods to evaluate EL
expressions. This class is the ADFUtil class. You can then call that helper class whenever you
must evaluate EL.
1. In the Application Navigator, expand Application Sources, right-click the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

oracle.storefront.ui package, and select New.


2. In the New Gallery, select General > Java Class and click OK.
3. Name the class ADFUtil and put it in oracle.storefront.ui.common.
4. Select the Public check box and click OK.
5. Replace all the code in the class with the following code: (You can copy it from
ADFUtil.txt in the \files subdirectory of your Labs directory.)
package oracle.storefront.ui.common;
u se
e to
n s
import java.util.Map;
i ce
b l el
import javax.el.ELContext;
fe ra
import javax.el.Expression;
a n s
import javax.el.ExpressionFactory;n - tr
import
a no eฺ
javax.el.MethodExpression;
import
h a s uid
javax.el.ValueExpression;
m ) nt G
l ฺ o
c tude
i
import javax.faces.context.FacesContext;
g ma is S
import oracle.adf.model.BindingContext;
o@ th
ฺv i n
import oracle.adf.model.DataControlFrame;

C (ac
d A
n o /**
Vi * Provides various utility methods that are handy to
* have around when working with ADF.
*/
public class ADFUtil {

/**
* When a bounded task flow manages a transaction (marked as
* requires-transaction, requires-new-transaction, or
* requires- existing-transaction), then the task flow must
* issue any commits or rollbacks that are needed.
* This is essentially to keep the state of the transaction
* that the task flow understands in synch with the state
* of the transaction in the ADFbc layer.
* Use this method to issue a commit in the middle of a task
* flow while staying in the task flow.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 5
*/
public static void saveAndContinue() {
Map sessionMap =

FacesContext.getCurrentInstance().getExternalContext().getSessio
nMap();
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

BindingContext context =

(BindingContext)sessionMap.get(BindingContext.CONTEXT_ID);
String currentFrameName =
context.getCurrentDataControlFrame();
DataControlFrame dcFrame =
context.findDataControlFrame(currentFrameName);
u se
e to
dcFrame.commit(); n s
i ce
dcFrame.beginTransaction(null);
b l el
}
fe ra
a n s
/**
n - tr
* Programmatic evaluation of EL.
a no eฺ
*
h a s uid
* @param el EL to evaluate
m ) nt G
l ฺ o
c tude
i
* @return Result of the evaluation
*/
g ma is S
o @ th
public static Object evaluateEL(String el) {

c ฺ vin FacesContext facesContext =


( a FacesContext.getCurrentInstance();
A C
n o d ELContext elContext = facesContext.getELContext();

V i ExpressionFactory expressionFactory =

facesContext.getApplication().getExpressionFactory();
ValueExpression exp =
expressionFactory.createValueExpression(elContext,
el, Object.class);
return exp.getValue(elContext);
}

/**
* Programmatic invocation of a method that an EL evaluates
* to. The method must not take any parameters.
*
* @param el EL of the method to invoke
* @return Object that the method returns

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 6
*/
public static Object invokeEL(String el) {
return invokeEL(el, new Class[0], new Object[0]);
}
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

/**
* Programmatic invocation of a method that an EL evaluates to.
*
* @param el EL of the method to invoke
* @param paramTypes Array of Class defining the types of the
* parameters

se
* @param params Array of Object defining the values of the
* parametrs
to u
* @return Object that the method returns
n s e
*/
i ce
public static Object invokeEL(String el,
b l el
Class[] paramTypes, Object[] params) { fe ra
a n s
FacesContext facesContext =
n - tr
no eฺ
FacesContext.getCurrentInstance();
a
ELContext elContext = facesContext.getELContext();
s uid
h a
) nt G
ExpressionFactory expressionFactory =
o m
c tude
i l ฺ
ma is S exp =
facesContext.getApplication().getExpressionFactory();
g
MethodExpression
th
i n o@expressionFactory.createMethodExpression(elContext,
ฺv
C (ac el, Object.class, paramTypes);
return exp.invoke(elContext, params);
d A
n o }
Vi
/**
* Sets a value into an EL object. Provides similar
* functionality to
* the &lt;af:setActionListener&gt; tag, except the
* <code>from</code> is
* not an EL. You can get similar behavior by using the
* following...<br>
* <code>setEL(<b>to</b>, evaluateEL(<b>from</b>))</code>
*
* @param el EL object to assign a value
* @param val Value to assign
*/
public static void setEL(String el, Object val) {
FacesContext facesContext =
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 7
FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =

facesContext.getApplication().getExpressionFactory();
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

ValueExpression exp =
expressionFactory.createValueExpression(elContext,
el, Object.class);
exp.setValue(elContext, val);
}
}
6. Right-click anywhere in the code editor and select Make to compile the class.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 8
Practice 18-3: Creating the Producer (Payload) Method
When the user clicks a category or subcategory in the tree, you must capture the current values
and store them. These are the values (payload) that you pass to ShoppingFlow and use on the
ProductCatalog page. In this practice, you create a JavaBean to encapsulate the current row
values. A method in this JavaBean becomes the payload method of the contextual event.
1. Create the new Java class.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. In the Application Navigator, expand Application Sources, right-click the


oracle.storefront.ui package, and select New.
b. In the New Gallery, select Java Class.
c. Name the class FODCategoryBean and put it in the
oracle.storefront.ui.bean package.
d. Make it public and use the Constructors from Superclass option. Click OK.
e. Add private variable definitions for the following:
u se
categoryId, subCategoryId (Number)
e to
categoryName, subCategoryName (String)
n s
i ce
el
At this point, the code should be:
a b l
public class FODCategoryBean {
fe r
private Number categoryId, subCategoryId;
a n s
private String categoryName, subCategoryName;
n - tr
a no eฺ
public FODCategoryBean() s id
super(); h a
) nt G
{
u
o m
c tude
}
i l ฺ
f. Generate accessors g mafor thesei s S
variables using either the toolbar button (on the
o
visual editor@pane) or t
the
h menu Source > Generate Accessors. Click the select all
i n
ฺv Click OK to generate the accessors.
button.
( a c
2. Add a method named onNodeClicked() that returns a bean with values set based on the
d ACvalues of the node that the user clicked: (You can copy it from onNodeClicked.txt in the
n o
Vi \files subdirectory of the Labs directory.)
/**
* Evaluates the currently selected node in the tree returns a
* bean representing that node.
*
* @return FODCategoryBean with all properties set
*/
public FODCategoryBean onNodeClicked() {
JUCtrlHierNodeBinding node =

(JUCtrlHierNodeBinding)ADFUtil.evaluateEL("#{node}");
Row nodeRow = node.getRow();

JUCtrlHierNodeBinding parentNode = node.getParent();


Row parentRow = parentNode.getRow();
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 9
Number categoryId, subCategoryId;
String categoryName, subCategoryName;
if (parentRow == null) {
// Root category selected
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

categoryId =
(Number)nodeRow.getAttribute("CategoryId");
categoryName =
(String)nodeRow.getAttribute("CategoryName");
subCategoryId = null;
subCategoryName = null;

se
} else {
// Sub-category selected
to u
categoryId =
n s e
(Number)parentRow.getAttribute("CategoryId");
i ce
categoryName =
b l el
(String)parentRow.getAttribute("CategoryName"); fe ra
a n s
subCategoryId =
n - tr
no eฺ
(Number)nodeRow.getAttribute("CategoryId");
subCategoryName =a
s uid
h a
) nt G
(String)nodeRow.getAttribute("CategoryName");
} o m
c tude
i l ฺ
g ma is S
th
setCategoryId(categoryId);
@
ฺv inosetSubCategoryId(subCategoryId);
( ac setCategoryName(categoryName);
AC setSubCategoryName(subCategoryName);
d
V ino return this;
}
3. JDeveloper prompts you to import the supporting packages. Make sure that you have the
following imports statements:
oracle.jbo.Row;
oracle.jbo.domain.Number;
oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;
oracle.storefront.ui.common.ADFUtil;
Important Note: If you are not prompted for the oracle.jbo.domain.Number
package, add it to the imports manually. Otherwise, the code will use the wrong Number
class and you will get errors when you call it.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 10
4. Compile the class and create a data control from it.
a. Right-click anywhere in the code editor and select Make. This compiles the class.
b. Right-click the bean (FODCategoryBean.java) in the Application Navigator and select
Create Data Control from context, or alternatively, just drag the bean from the
Application Navigator to the Data Control panel.
c. Check the Data Controls panel to ensure that the bean was added. If it is not there,
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

click the Refresh icon on the Application Navigator.


The Data Control panel should look something like the following:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 11
Practice 18-4: Initiating the Contextual Event
The ProductCategory page starts the event sequence. When a user clicks a node in the
Category tree, an event is raised, which is managed by the FODShoppingDashboard page. In
this practice, you set up the ProductCategory page to initiate the event.
1. Call the onNodeClicked() method when the user clicks a node in the tree.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. Open the ProductCategory page fragment.


b. Drag the FODCategoryBean > onNodeClicked() method from the Data Controls
panel to the af:commandLink, and select Bind Existing Link.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
c. Click OK to accept the default values on the Confirm Component Rebinding page.
2. ( a
Add an event to the page named FODSelectCategory that will be registered when the user
A C
clicks the node.
n o d a. While still on the ProductCategory page, click the Bindings tab.
V i b. Expand Bindings in the Structure window.
c. Insert events (an event list) inside onNodeClicked (use the context menu).

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 12
d. Insert an event inside the event list and set the name property to
FODSelectCategory.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

The Binding Structure should look like the following:

u se
e to
n s
i ce
b l el
f er a
s
ainnthe Category Tree calls the
You now have specified that clicking a node at run time
- t r
n on ฺ
onNodeClicked() method and raises the FODSelectCategory event.

s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 13
Practice 18-5: Creating the Consumer (Handler) Method
In this application, the producer of the event is the ProductCategory page (the category tree).
The consumer of the event is the ProductCatalog page.
In this practice, you create the method that is used by the consumer of the event. It handles the
information that is passed to the consumer region (the payload) as follows:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

• Sets the requestScope variables to reflect which Category was selected in the tree
• Encapsulates the requestScope variables in a bean that is used by the consumer of
the event (the ProductCatalog page)
To create this handler method, perform the following steps:
1. Create a new Java class for the bean as you did for the producer bean. Name the class
FODShoppingDashboardBean and put it in the oracle.storefront.ui.bean
package. Make it public and use the Constructors from Superclass option.
2. Add the refreshCategory() method. This method uses an ADFUtil method to set the u se
requestScope variables to hold the category and subcategory ID and name: (You can
e to
copy it from refreshCategory.txt in the \files subdirectory of the Labs directory.) n s
i ce
/**
b l el
* Used as a consumer to a contextual event, changes the
fe ra
* parameter values passed to the local area region and forces
a n s
* a refresh in that area.
n - tr
*
a no eฺ
a
* @param category Selected category
h s uid
*/ m ) nt G
l ฺ o
c tude
i
public void refreshCategory(FODCategoryBean category) {
/* g ma is S
o @ th
vin
* For the selected category, set requestScope

a c ฺ * variables.
C ( * These variables are used as parameters to the local
d A
i n o * area region.
V */
ADFUtil.setEL("#{requestScope.CategoryId}",
category.getCategoryId());
ADFUtil.setEL("#{requestScope.SubCategoryId}",
category.getSubCategoryId());
ADFUtil.setEL("#{requestScope.CategoryName}",
category.getCategoryName());
ADFUtil.setEL("#{requestScope.SubCategoryName}",
category.getSubCategoryName());

/** #{requestScope.refreshLocalArea} is used as the EL to


* control whether the local area region is refreshed. By
* setting this to true, the region will be forced to refresh
* with the new category.
*/
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 14
ADFUtil.setEL("#{requestScope.refreshLocalArea}",
Boolean.TRUE);
}
3. JDeveloper prompts you to import the supporting package. Import the following:
oracle.storefront.ui.common.ADFUtil;
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

4. As you did with the other bean, compile the class and create a data control from it. The
Data Control panel should now look like this:

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 15
Practice 18-6: Mapping the Contextual Event
Now that you have created the bean and added it to the Data Control panel, in this practice, you
add a method action binding so that you can use it on the FODShoppingDashboard page. The
FODShoppingDashboard page is the page that contains both the Category region and the
Shopping region, so it is responsible for coordinating the event. To accomplish this, you also
add an event map to the page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Add a method action binding to the refreshCategory() method.


a. Open the FODShoppingDashboard page.
b. Click the Bindings tab.
c. Click Create control bindings to add a Generic Bindings > methodAction
binding. Select FODShoppingDashboardBean.refreshCategory() as the
operation. Leave the category parameter’s value blank.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
d. Click OK to create the binding.
2. c ฺ vin
Create an event map to orchestrate the contextual event.
( a
A C
a. On the Bindings tab for FODShoppingDashboard, right-click the top-level node in

n o d the Structure window and select Edit Event Map.


V i

b. In the Event Map Editor, click Add a New Event Entry .


c. In the Add New EventMap Entry dialog box:

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 16
1) From the Producer drop-down list, select FODShoppingDashboardPageDef >
ProductCategoryFlow1 > ProductCategoryPageDef.onNodeClicked.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2) Select FODSelectCategory as the Event Name. (This should be selected by


default, because it is the only event that you have defined.)
3) Select FODShoppingDashboardPageDef > refreshCategory from the u se
Consumer drop-down list. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
th section, click Add Consumer Parameter to define
o@ namedParams
4) In the Consumer
ฺ v i n
a parameter category with a value of #{payLoad}. (You can use the
c
(a Expression Builder to select Payload Data > payLoad.) Click OK.
A C
n o d
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 17
d. Click OK to create the event mapping in the containing FODShoppingDashboard page.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
e. Click OK again.
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 18
Practice 18-7: Passing Values Through Region Parameters
That completes building the event map and defining the producer and consumer methods. Now
you must set ShoppingFlow to be refreshed based on a requestScope parameter and to
accept the other parameters needed by the ProductCatalog page.
The handler method that you defined for the event sets several requestScope variables. In
this practice, you define region parameters to pass these variables into the Shopping region.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

The region parameters have the same name as the task flow parameters that you defined in the
first practice for this lesson. So the values come through the event to requestScope variables
and are passed to region parameters. The region parameter values are passed to the task flow
parameters, which in turn set the pageFlowScope variables that the ProductCatalog page uses
to conditionally render tables and breadcrumbs, as you defined in an earlier practice.
1. One of the tasks accomplished by the refreshCategory() method in the
FODShoppingDashboard bean is to set a Boolean requestScope variable named
refreshLocalArea to true. Set a refresh condition in the ShoppingFlow region to make u se
use of the value of this variable, so that the region is refreshed only if refreshLocalArea
e to
is set to true. n s
i ce
a. Still in the FODShoppingDashboard page definition (the Binding tab of the page),
b l el
select Executables > ShoppingFlow1 in the Structure window.
fe ra
b. Set RefreshCondition to #{requestScope.refreshLocalArea}.
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
C
2.A Set region parameter values to the requestScope values that are set by the
n o d
Vi refreshCategory() method in the FODShoppingDashboard bean.
a. Click the Parameters tab in the Property Inspector. Note that the task flow binding
parameters are listed.
b. Set the value property of the parameters to the following values.

Name Value
CategoryId #{requestScope.CategoryId}

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 19
CategoryName #{requestScope.CategoryName}
SubCategoryId #{requestScope.SubCategoryId}
SubCategoryName #{requestScope.SubCategoryName}
3. Run the page and test the functionality.
a. You should see that when you click a Category in the tree, ProductCatalog displays
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

the related SubCategories.


b. When you click a SubCategory, the page displays the related Products.
c. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.
4. Extra credit (if you have time): When you click a Category in the tree, you should notice
that the tree seems to be refreshed as well. Prevent that from happening so that only the
ProductCatalog region is refreshed.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 20
Practice 18-8: Modifying the JSF Life Cycle (Optional Exercise)
If you have time: In this practice, you modify the JSF life cycle to print out a message
whenever the user navigates to a new page. In a “real” application, you could use a similar
modification to call a routine to, for example, perform some cleanup activities.
1. In the oracle.storefront.ui.common package, create a new Java class named
StorefrontPhaseListener.java that implements the PhaseListener interface and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

displays a message when the view ID of a page changes.


a. Right-click oracle.storefront.ui.common to invoke the New Gallery, select Java
Class in the General category, and then click OK.
b. In the Create Java Class dialog box, enter a name of StorefrontPhaseListener,
and leaving the default options, click OK.
c. Right-click the editor and select Source > Implement Interface.
d. On the Hierarchy tab of the Implement Interface dialog box, select javax > faces >
event > PhaseListener and click OK. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
e. g maattribute
Add a private String i s Snamed storedViewId to store the view ID by adding
o@
the following t h
on the line just after the first left brace:
i n
ฺv String storedViewId = null;
(ac
private

A C
f. Modify the getPhaseId() method to return the PhaseId of whatever life-cycle phase

n o d being executed with the following code:


Vi public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
g. Modify the afterPhase() method to store the view ID when the view is first restored:
public void afterPhase(PhaseEvent phaseEvent) {
if (phaseEvent.getPhaseId() == PhaseId.RESTORE_VIEW) {
storedViewId =
phaseEvent.getFacesContext().getViewRoot().getViewId();
}
}

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 21
h. Modify the beforePhase() method so that just before the page is rendered a
message appears if the current view ID is not the same as the stored view ID:
public void beforePhase(PhaseEvent phaseEvent) {
if (phaseEvent.getPhaseId() == PhaseId.RENDER_RESPONSE) {
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

String viewId =
phaseEvent.getFacesContext().getViewRoot().getViewId();
if (storedViewId != null &&
!viewId.equalsIgnoreCase(storedViewId)) {
System.out.println("Changing pages");
}
storedViewId = null;
}
u se
}
e to
2. Register the new phase listener with JavaServer Faces. n s
i ce
a. Open faces-config.xml in the editor by double-clicking it in the Application
b l el
Navigator (under WebContent > WEB-INF).
fe ra
b. Click the Overview tab.
a n s
c. On the Life Cycle tab, click Add n - tr
to add a Phase Listener.
d. no eฺ
Enter the complete path to the phase listener and the class name:
a
h a s uid
oracle.storefront.ui.common.StorefrontPhaseListener.
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
3. Test the functionality by invoking the application and changing views. Because you have
only one view activity in the application, with all others being part of a region on the same
page, you must add another page to the application to test it.
a. Open adfc-config and add a view activity called Start.
b. Add a control flow case from Start to FODShoppingDashboard whose from-
outcome is start.

c. Create the Start.jspx page by double-clicking the Start view activity in the editor.
Select the Blank Page option.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 22
d. Add a button to the page labeled Start Shopping and set its Action to start.
e. Run the Start page from the adfc-config diagram.
f. When the page appears, switch back to JDeveloper, and right-click the JDeveloper log
and select Clear.
g. Switch back to your browser window and click Start Shopping. You should see the
message in the log, “Changing pages.”
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

h. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 23
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 18


Chapter 18 - Page 24
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 19
- r
on ฺ
Chaptern19
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 2
Practices for Lesson 19: Implementing Transactional Capabilities
Practices Overview
In this practice, you complete the application by adding transaction management. So far, the
application navigates to all the pages and displays data, but the commit functions are missing.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

There are three places in the application where a commit is needed:


• The first is “Add to Cart,” where the user adds items to the cart. So far, the user can add
items but they are not persisted.
• The second area is Checkout.
• The third area is being able to update, delete, and add Suppliers.
If you successfully completed all sections of the previous practice, you can continue working in
the same project. However, if you prefer to start with a clean application that contains everything
completed up to the start of this lesson, open Storefront-19.jws and edit the database
u se
information as described in step 4 of Practice 2-4.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 3
Practice 19-1: Saving the Shopping Cart
In this practice, you add a commit to the shopping cart functionality to persist items that are
added to the cart.
1. Use the Commit operation of FODShoppingCartAMDataControl to commit items after
adding them to the cart.
a. Open the ShoppingCartFlow.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. From the Data Controls panel, drag the Commit operation from
FODShoppingCartAMDataControl > Operations to the ShoppingCartFlow page flow.
c. Set the fixed-outcome property to done.
d. On the diagram, select the done control flow case and in the property inspector,
change its to-activity-id to Commit.
e. Add a Control Flow Case labeled done from Commit to ShoppingCart. Set the from-
outcome property to done.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
2. Test a
( the functionality:
C
A a. Run FODShoppingDashboard from the adfc-config task flow.
n o d
V i b. Add an item to the cart; it should remain in the cart when you redisplay it and when
you rerun the application.
c. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 4
Practice 19-2: Updating, Deleting, and Displaying Details of Shopping
Cart Items
In this practice, you add data management to the shopping cart. You add the ability for users to
update or delete a line item or to display details about it. You use a bean that contains a single
method to perform a delete followed by a commit. By using this method, a single button click
executes both parts of the transaction. Without it, you would have to either click two buttons or
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

wire the two functions together.


1. Add a bean named FODCommitDeleteBean to the oracle.storefront.ui.bean
package.
a. In the Applications Navigator, right-click the oracle.storefront.ui\bean
directory and select New > JavaClass.
b. Name the class and set the package to oracle.storefront.ui.bean.
c. Make it Public and keep other default options.
u se
2. Add a method named onDeleteItem that calls the ADFUtil.invokeEL() helper
e to
method to execute the EL expression that you pass in as a parameter. In this case, it will n s
i ce
execute a Delete and a Commit. Note that the Delete and Commit methods must be in the
Page Definition Bindings for any page that uses them. b l el
a. Add the following code: (You may copy the code from onDeleteItem.txt in the fe ra
\files subdirectory of the Labs directory.) a n s
n - tr
/**
a noroweฺin the Shopping
* Deletes the current selected
h a s uid Cart.
*
m ) nt G

* @param actionEvent
l o
c tude
i
*/
g ma is S
th
o@ onDeleteItem(ActionEvent

publicv i nvoid actionEvent) {
(a c ADFUtil.invokeEL("#{bindings.Delete.execute}");
A C ADFUtil.invokeEL("#{bindings.Commit.execute}");
n o d
Vi
}
b. Include the following imports as JDeveloper prompts you:
javax.faces.event.ActionEvent
oracle.storefront.ui.common.ADFUtil
c. Right-click anywhere in the code and select Make.
3. Register the bean as a managed bean.
a. Open the adfc-config.xml pageflow.
b. Click the Overview tab.
c. Click the Managed Beans tab.
d. Add a managed bean by clicking the Add icon with the following properties:

Name FODCommitDeleteBean
Class oracle.storefront.ui.bean.FODCommitDeleteBean
Scope request
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 5
4. Complete the ShoppingCart page by adding buttons for Update, Delete, and Details; these
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

buttons should relate to the rows of the table. Add a panel collection around the table to
contain the buttons.
a. Open the ShoppingCart page fragment.
b. Surround the af:table with a Panel Collection.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
c. Insert a toolbar inside Panel Collection
h a s facetsu>idtoolbar.
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi
d. Drag the FODShoppingCartAMDataControl > Commit operation to the toolbar as an
ADF Toolbar Button. This adds the button and also adds the Commit operation to the

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 6
page definition.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
e. Set the following properties on the toolbar button:
b l el
Id updateMenu
fe ra
a n s
Text (optionally use
the resource bundle)
Update
n - tr
Action <default> a no eฺ
h a s uid
Disabled ) default
Reset to
m n G
t value
o e
f. Add a second toolbar a ilฺc Stotthe
button udtoolbar. This time add it from the Component
m and select
Palette, or right-click
g is insert inside.
g. o @
Set the following t h
properties on the second toolbar button:
ฺv i n
C (aIdc deleteMenu

d A Text (use the Delete


n o resource bundle)
Vi Action <default>
ActionListener #{FODCommitDeleteBean.onDeleteItem}
(Use the Edit option.)

h. Add a third toolbar button and set the properties as follows:


Id Leave blank
Text (optionally use Details
the resource bundle)

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 7
Action <default>
5. The method you added in the managed bean uses a commit binding and a delete binding.
When you added the commit button from the Data Control panel, JDeveloper added the
commit binding for you. Now manually add the delete binding to the page.
a. Click the Bindings tab in the editor of the ShoppingCart page fragment.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the Bindings section, click Add .


c. In the Insert Item dialog box, select Generic Bindings > action and click OK.
d. In the Create Action Binding dialog box:
1) Expand FODShoppingCartAMDataControl and select ShoppingCart1.
2) From the “Select an Iterator” drop-down list, select ShoppingCartItem1Iterator.
3) From the Operation drop-down list, select Delete and click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
a
e. (In the Property Inspector, change the InstanceName to
C
A FODShoppingCartAMDataControl.ShoppingCart.ShoppingCartItem1.
n o d6.
V i Use partial page rendering to refresh the table to show the changes when the user clicks
either Update or Delete.
a. Click the Design tab in the editor.
b. Select af:table in ShoppingCart.jsff and using the Edit option, set PartialTriggers
on the table to include up dateMenu and deleteMenu.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 8
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
7. Enable the quantity to be updated.
fe ra
a. With af:table still selected, click the Edit Component Definition icon on the
a n s
- tr
Property Inspector and ensure that the Row Selection check box is selected, and click
n
OK.
a no eฺ
h a s uid
b. Select af:outputText - #{rowQuantity} and convert it to an Input Text.
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
c. Remove the value from the Label attribute on the Input Text.
8. Test the functionality.
a. Run FODShoppingDashboard, add an item to the cart, update a quantity or two,
delete an item by using the Delete button (be sure to leave at least one item in the
cart), and so on. (The only button that you have not yet connected is the details
button—you do this next.)
When you update a quantity and click the Update button, you should notice that the
line item total also changes.
b. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.
9. Use a pop-up window to display the details of the item when a user clicks the Details
button.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 9
a. In ShoppingCart.jsff, drag a Popup from the Component Palette to af:panelCollection
in the Structure window.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Set the following properties in the pop-up window:


Id ProductDetails
ContentDelivery
se
LazyUncached
c. Insert a Dialog in the pop-up window. to u
d. Drag FODShoppingCartAMDataControl > ShoppingCart1 > ShoppingCartItem1 to n s e
af:dialog as an ADF Read-only Form. i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
(1)a Do not include Navigation Controls or a Submit button.
C
A 2) Include the following columns, in the same order:
n o d
V i ProductName
Description
AdditionalInfo
ListPrice
3) Delete other Columns.
e. Set the following properties on af:dialog:
Type Ok
Title #{bindings.ProductName.inputValue}
(use Expression Builder)
f. Add a call to the pop-up window from the Details button:
1) Click back on the ShoppingCart page to close the pop-up window.
2) Insert a Show Popup Behavior operation in the Details button.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 10
3) Using the Edit option, set PopupId to ProductDetails.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
10. Test the functionality.
a n s
- tr
a. When you click Details on the ShoppingCart page, the productDetails pop-up should
n
display the dialog box.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

b. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 11
Practice 19-3: Controlling Transactions in the CheckoutFlow
In this practice, you add transactional capability to the CheckoutFlow.
1. Implement transaction control in the CheckoutFlow task flow, starting a new transaction
when entering the flow and terminating with either a commit or a rollback.
a. Open the CheckoutFlow, and in the Structure pane, select the task-flow-definition
node.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. On the Behavior panel of the Property Inspector, set the Transaction property to
Always Begin New Transaction. This means that when this flow is called, it starts a
new transaction.

u se
e to
n s
li ce
l e
b property to
c. Select the SubmitOrder task flow return and set the End Transaction
e r a
commit.
a n sf
d. Select CancelOrder task flow return and set the End
n - trTransaction property to
rollback.
a no eฺ
2. Run the FODShoppingDashboard page tostest the checking
id madeouttosteps. When you click
ha t you
Submit on the Confirmation page, any) changes u
G application, this could, for example,
have the shipping and billing
information are committed. In a o m
real n
SOA-integrated
ilฺc back-end
commit an order and startasome t u deprocessing.
g m is S
o@ th
v i n
( acฺ
AC
d
V ino

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 12
Practice 19-4: Adding CRUD Functionality for Suppliers (Optional
Exercise)
On the ManageSuppliers flow, you have already added the functionality to create a new supplier
and to update supplier information, but you have not added the ability to commit the updates
and deletes. In this practice, you implement the ability to add, update, and delete suppliers.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

This practice is optional because the steps are similar to what you have done previously.
If you choose not to add CRUD functionality for Suppliers, you must begin the practices
for the next lesson by opening the starter application.
1. Add transaction control to the ManageSupplierFlow task flow as you did with the
ShoppingCartFlow, with the commit and rollback functionality.
a. Open ManageSupplierFlow in the editor.
b. In the Structure window, select task-flow-definition – ManageSupplierFlow.
c. In the Property Inspector, click the Behavior tab and set transaction to Always Begin
New Transaction. u se
e to
d. In the editor, select the Save task flow return and set its End Transaction property to
n s
commit. i ce
e. In the editor, select the Cancel task flow return and set its End Transaction property b l el
to rollback.
fe ra
f. Save your work. a n s
n - tr
2. Add the ability to delete a supplier to the BrowseSuppliers page fragment.
a no eฺ
a. Open the BrowseSuppliers page fragment in the editor.
h a s uid
b. Check whether the table has row selection enabled by selecting af:table in the
Structure window, and theno m ) Editnt Gin the Property Inspector. Ensure that the
clicking
Row Selection check i l ฺ cis selected.
u d e
a box
mpanel, t
S FODSupplierAMDataControl > Supplier1 >
c. g
In the Data Control
t h i s
expand
Operations
i n o@and drag the Delete operation to the toolbar in the toolbar facet of the
PanelฺvHeader on the page, creating an ADF Toolbar Button.
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 13
d. Set the following properties on the button:
Id deleteSupplier
ActionListener Set to the onDeleteItem method of the
managed bean (Use the method expression
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

builder from the list to select it.)

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
e. The onDeleteItem() method callsa
h s uid
bindings.Delete.execute and
bindings.Commit.execute. When ) G
yout added the delete operation as a button, the
Delete binding was added,
l ฺ omtheredisenon Commit binding. Add a Commit binding to
cbut
the page definition. a i S tu
g m s
1) Click the
o @ hi
Bindingsttab.
n Bindings section, click Create control binding .
vithe
2)cฺIn
C (a
3) In the Insert Item dialog box, select action and click OK.

n o dA 4) In the Create Action Binding dialog box:


V i a) Select the FODSupplierAMDataControl.
b) Select the Commit operation from the drop-down list.
c) Click OK.

f. To improve the appearance of the buttons, return to the Design view, and change the
Width of the Panel Header to 500 Pixels.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 14
g. To ensure that the table is refreshed after the record is removed, use the Edit option,
to set the Partial Triggers property on the table, to the ID of the Delete button.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
h. Save your work. b l el
3. Test the functionality. fe ra
a n s
n - tr
a. Run FODShoppingDashboard from the adfc-config task flow.

the New Supplier and Delete buttons. a no eฺ


b. Click the Suppliers tab and resize the left panel of the panel splitter until you can see

h a s uid
c. Select the supplier that you previously added and click Delete. You should see that the
m
supplier is removed from the row.
) nt G
l ฺ o
c tude
i
d. Close the browser. In the JDeveloper log pane, click the Target URL link to rerun the
page. g ma is S
o @ th
e. Click the Suppliers tab. You should see that the supplier you deleted is no longer in
ฺ vin
the table even when the data is required.
c
( a
f. When finished, close the browser and undeploy the application as described in step
A C 6(i) of Practice 2-4.
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 15
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 19


Chapter 19 - Page 16
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anLesson 20
- r
on ฺ
Chaptern20
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 2
Practices for Lesson 20: Implementing Security in ADF BC
Applications
Practices Overview
In the practices for this lesson, you set up the application to use security. You create users and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

roles in an identity store, and you assign permissions to roles. You also create login and error
pages. You then use ADF security to manage access to pages, task flows, and entity objects,
and you programmatically access the security context by using global security expressions and
a security proxy bean.
If you successfully completed all sections of the previous practice, you can continue working in
the same project. However, if you prefer to start with a clean application that contains everything
completed up to the start of this lesson, open Storefront-20.jws and edit the database
information as described in step 4 of Practice 2-4.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 3
Practice 20-1: Configuring the Application to Use ADF Security
In this practice, you set up the application to use ADF security for both authentication and
authorization.
1. Examine the existing files in the Descriptors node of the Application Resources panel.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2. Invoke the Configure ADF Security Wizard and configure the application to use ADF u se
security for both authentication and authorization. e to
n s
a. With the StorefrontUI project selected in the Application Navigator, from the main
i ce
menu, select Application > Secure > Configure ADF Security.
b l el
b. On the ADF Security page of the wizard, select the ADF Authentication and
fe ra
Authorization option, and then click Next.
a n s
- tr
c. On the Authentication Type page of the wizard, select the Form-Based
n
no eฺ
Authentication option and the Generate Default Pages check box. Click Next.
a
h a s uid
d. On the Automatic Policy Grants page of the wizard, select the No Automatic Grants
option, and then click Next. ) nt G
o m
c tude
e. On the Authenticated Welcome page, select Redirect upon successful
i l ฺ
g ma is S
authentication, and on the welcome page, select the
/oracle/storefront/ui/pages/FODShoppingDashboard.jspx page. Click
Next. o @ th
c ฺ vin
f. The Summary page of the wizard displays a list of files that will be changed or created.
( a
Click Finish to create the security configuration.
A C
n o d
V i

g. Click OK to acknowledge the Security Infrastructure Created dialog box.


h. Save your work.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 4
3. Reexamine the files in the Application Resources panel. You can see that the Configure
ADF Security Wizard created a new file, jazn-data.xml.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

4. If you look in the file system, you can compare the modified dates to see which files have
been changed.
a. First, using Windows Explorer, look in the Storefront-20 > .adf > META-INF
u se
subdirectory of your application resource descriptor. You could see that the adf-
e to
config.xml file has just been changed.
n s
b. i ce
Next, look in the Storefront-20 > src > META-INF subdirectory of your application
l
resource descriptor. You should see that all files except for weblogic-
a b le
application.xml have been changed.
fe r
n s
c.
n
application. You can see that web.xml and weblogic.xml- tra subdirectory
Finally, look in the StorefrontUI > public-html > WEB-INF of your
have been changed.
(Actually, weblogic.xml is a new file.) a n
o ฺ
a s i d e
) h nt G u
m
co tude
i l ฺ
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 5
d. The Application Navigator displays the corresponding files.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
li ce
l e
bthe Configure ADF
e. Note that the changed files are the ones that the Summary page of
e r a
Security Wizard reported to be created or changed.
a n sf
5. In the JDeveloper Application Resources panel, double-click
n - tra newly
jazn-data.xml to open it,
and then click the Source tab to examine the entries.
n o ฺIt is created file that contains:
• The default realm name for the optionalsXML a identity
i d estore
• The policy store for the Storefront-20
a u
) h application,
G consisting of application roles and a
m
o de
policy. The policy grants permissions onn t
resources (task flows and pages) to the
application roles. i l ฺ c tu
m a S
6. g
Similarly, using the Source tab,
@ t s
hi examine:
o
c ฺ vin and the context
a. jps-config.xml:
instances,
Definitions have been added for service providers, service
for Java Platform Security.
( a
AC
b. adf-config.xml: The JaasSecurityContext entry has been added, specifying
d that both authentication and authorization are enforced.
V ino 7. Similarly, from the Application Navigator, open web.xml and weblogic.xml (StorefrontUI
> Web Content > WEB-INF):
a. web.xml has added initialization parameters for JpsFilter, along with a definition
for the adfAuthentication servlet, a security constraint, the login configuration
(form-based with the login and error pages), and a security role (valid-users).
b. weblogic.xml is a newly created file that assigns the principal name users to the
valid-users security role.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 6
Practice 20-2: Defining Users in the Identity Store
In this practice, you define some users to test security.
1. Create the following users in the default security realm, using welcome1 as the password
for each: DRAPHEAL, sking, bernst, and pgamer.
a. With the jazn-data.xml file open in the editor, click the Users and Roles tab.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Click the Users tab and in the Users pane, click Add to create new users.
c. In the Add User form, enter the name (such as DRAPHEAL) and the credentials
(welcome1).

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
Repeat steps b g
ma each i s S
d.
o @ and c for
t h user; the users appear in the Users list. Instead of
pgamer,
ฺ v inyou can add your own name if you would prefer to.

C (ac
d A
n o
Vi

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 7
Practice 20-3: Defining Enterprise Roles
In this practice, you define the enterprise roles that you want to be able to access the
application. To do so, you think about the functions and groups of functions that users must
perform, which fall into four categories:
• Managers in the company must view and update information about suppliers, but they
do not need to delete suppliers and they do not need to access the shopping portal.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

• Clerks in the company must be able to read, update, and delete supplier information,
but they do not need to access the shopping portal.
• Customers must be able to shop and to view the list of suppliers, but do not need to
update or enter new suppliers.
• Application developers must be able to temporarily access everything for testing
purposes. There is currently one developer working on the application.
1. Create the enterprise roles manager, clerk, customer, and developer.
u se
a. Click the Enterprise Roles tab, and then click Add in the Roles panel. e to
n s
b. In the Add Role dialog box, enter the Name manager.
i ce
c. Repeat steps a and b to add the other three roles; the roles appear in the Enterprise
b l el
Roles list along with the test-user role that the security configuration created.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 8
2. Add the following users to the enterprise roles:
manager sking
clerk bernst
customer DRAPHEAL (use this exact name)
pgamer (or your own name if you created it as a user)
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

developer
a. In the Enterprise Roles pane, click the Members tab.
b. In the Enterprise Roles list, select manager.
c. On the Member tab, from the Add list, select Add User.
d. In Select Users, select sking and click OK.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
e. Repeat steps b, c, and d foroeach eindicated above.
i l ฺ c turole
d
m a correspond
3. Create application roles that S to the identity store roles (manager, clerk,
g s
customer, and developer)hiprefixed by fod_, such as fod_customer. Also create a
t
@ called fod_user.
n
fifth application
i orole
a. a
( cฺvApplication Roles at the left, and then click the Add icon in the Application
Select
A C Roles panel.
Vi nod b. Add the same roles as you did in the enterprise roles, prefacing the role name with
fod_, such as fod_manager.
c. Add another application role named fod_user.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 9
4. To each application role, add its corresponding enterprise roles (for example, add
customer to fod_customer).
a. Select fod_manager in the Roles pane.
b. Click the Members tab and select the Add enterprise role from the Add button.
c. Select the manager role and click OK.
d. Repeat steps a, b, and c for each role you created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
e. Then add clerk, customer, manager, and developer to fod_user.
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

5. Save your work.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 10
Practice 20-4: Implementing Security on Task Flows and Pages
In this practice, you grant to the roles the appropriate access to task flows and pages.
1. Grant managers, clerks, and developers access to the function of updating suppliers.
a. In the editor for the jazn-data.xml file, click the ADF Policies tab.
b. Select the ManageSupplierFlow task flow, and in the Granted To Roles column, click
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Add Application Role .

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
a box,Sselect the check boxes for fod_manager, fod_clerk,
c. In the Select Roles dialog
g m
and fod_developer, andhthen is click OK.
@ t
allothe roles do not appear in the Select Roles dialog box, close jazn-
Note: Ifin
ฺ v
( ac
data.xml and reopen it. The roles should then appear.

AC
d
V ino

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 11
d. By default, each selected role is assigned with the View Action. Keep this option
selected.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2. Grant customers and developers access to the shopping application.


a. In the editor, select ShoppingCartFlow.
b. Add the fod_customer and fod_developer application roles.
c. If necessary, delete the test-all role.
u se
d. Repeat steps a and b for CheckoutFlow and ShoppingFlow.
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
3. Grant all roles access to displaying the
o m e n tG
) following flows.
a. Select ShowSuppliersFlow.
a i lฺc tud
b. Add the fod_user
g mapplication
i s Srole.
c. If necessary,o@ t h
delete the test-all role.
i n
( a cฺv steps a and b for ProductCategoryFlow.
d. Repeat
4. Ensure that all users can access the FODShoppingDashboard page.
d ACa. Click the Web Pages tab.
Vi no b. Select the FODShoppingDashboard page.
c. Click the Add icon, and then add the fod_user application role.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 12
Practice 20-5: Testing Application Authentication and Authorization
In this practice, you test the authentication and authorization that you have set up.
1. Test authentication by entering incorrect credentials.
a. Open adfc-config in the editor.
b. Right-click the FODShoppingDashboard page and select Run.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Note: If you encounter an error when running the application, undeploy the application
and then terminate the default server. You do this the same way you undeploy an
application, except that you select IntegratedWebLogicServer instead of an application.
Then rerun the application.
c. On the login page, enter a fake username and password, and then click Submit.

u se
e to
n s
i ce
b l el
The error page should display the message:
fe ra
a n s
n - tr
a no eฺ
Note: When using Internet Explorer, you
a s may receive
u i d an HTTP error instead of seeing
the error page.
m ) h nt G
2. Test authorization.
i l ฺ co tude
m a button.
a. Click the browser’s Back S
b. On the login@ g
page, enter
t h is username
the sking, a valid user who is not authorized to
use thein o the password welcome1, and then click Submit.
c
The ฺ v shopping application. Enter
FODShoppingDashboard page appears, but the shopping application is not
( a
A C visible. You see data only when you click the Suppliers tab.

Vi nod Note: If you encounter an error when you enter the login information after using the
Browser’s Back button, rerun the application.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 13
c. Click the Suppliers tab, and then click the SupplierId in one of the rows. The supplier
detail is shown.
d. When finished, close the browser and undeploy the application as described in step
6(i) of Practice 2-4.
e. Run the application again and enter credentials for DRAPHEAL, who has access to the
shopping application. The FODShoppingDashboard page should then appear with the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

shopping application visible.


f. Click the Suppliers tab, and then click the SupplierId in one of the rows. You should
receive an error indicating that the authorization check failed, because DRAPHEAL does
not have access to the ManageSupplierFlow task flow.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
g.
c ฺ vin
When finished, close the browser and undeploy the application as described in step
6(i) of Practice 2-4.
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 14
Practice 20-6: Implementing Entity Object Security
1. Because suppliers, clerks, and managers (also the application developer) all have access
to the Suppliers data, secure the entity object and grant the appropriate permissions.
Managers should not be able to delete supplier records.
a. Select SupplierEO in the Application Navigator.
b. In the Structure window, right-click SupplierEO and select Edit Security.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
c.
fe
In the Edit Security dialog box, enable security on all operations, and then click OK. ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d d. In the Structure window, right-click SupplierEO and select Edit Authorization.
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 15
e. In the Edit Authorization dialog box, grant the following privileges:

Privileges Roles
Read fod_user
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Update fod_clerk, fod_developer, fod_manager


Delete fod_clerk, fod_developer

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
f. Click OK.
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 16
Practice 20-7: Testing Entity Object Security
In this practice, you test entity object security in the Business Components Browser.
1. Test the implementation of read-only access to the SupplierEO entity object.
a. In the adfc-config task flow diagram, right-click FODShoppingDashboard and select
Run.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. In the login dialog box, enter the username DRAPHEAL, whose customer role has
read-only access to SupplierEO. Enter the password welcome1 and click Submit.
c. Click the Suppliers tab. You should note that the Delete button is disabled.
d. Click New Supplier. You should receive an authorization error.

u se
e to
n s
i ce
e. Close the browser and run the application again, this time logging in as sking, who
has the manager role. Click the Suppliers tab. You should see that the Delete button b l el
is disabled. However, when you click New Supplier, or when you click a supplier ID fe ra
a
link, you should be able to navigate to the New Supplier or the Update Supplier n s
window. n - tr
f. a no eฺ
Close the browser and click the target URL in the Running Log pane to relaunch the
application in your browser.
h a s uid
g. m ) nt G
This time log in as bernst, who has the clerk role, or as pgamer, who has the
l ฺ o
c tude
i
developer role. Click the Suppliers tab. You should see that the Delete button is
ma is S
now enabled. Also, when you click New Supplier, or when you click a supplier ID link,
g
@ th
you should be able to navigate to the New Supplier or the Update Supplier window.
o
h.
c ฺ vin
Close the browser and undeploy the application.
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 17
Practice 20-8: Accessing Security Context Programmatically
In this practice, you use the SecurityContext API to retrieve security information
programmatically.
1. In the Application Navigator, in the oracle.fod.storefront.module package,
double-click BaseApplicationModuleImpl.java to open it in the editor.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

2. Add a method to retrieve the username from the security context.


a. Add the following code just above the closing right brace:
public String getUserName() {
return
ADFContext.getCurrent().getSecurityContext().getUserName().toUpp
erCase();
}
b. Press Alt + Enter if prompted to import oracle.adf.share.ADFContext. u se
3. Add a method to determine whether the user is in a certain role. e to
n s
a. Add the following code just above the closing right brace:
i ce
public boolean isUserInRole(String role) { b l el
return fe ra
ADFContext.getCurrent().getSecurityContext().isUserInRole(role); a n s
n - tr
noof FODShoppingCartAM
}

s a
b. Expose the added methods to the client interface
d e ฺ application
module. a
h t Gu i
1) In the Application Navigator,
)
m double-click
n FODShoppingCartAM to open it in the
ฺ c o d e
editor.
a il Stu
m
g tab.this
2) Click the Java
3) Ininthe
@
o Client Interface section, click Edit .
ฺ v
( ac4) In the Edit Client Interface dialog box, shuttle getUserName():String and
C isUserInRole(String):boolean from the Available list to the Selected list, and

n o dA then click OK.


V i

5) Save your work.


4. Test the functionality.
a. In the Application Navigator, right-click FODShoppingCartAM and select Run from the
context menu.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 18
b. In the JAAS Security login dialog box, enter DRAPHEAL as Principal and welcome1 as
Credentials, and then click OK.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. In the Business Components Browser, double-click FODShoppingCartAM.


d. Select getUserName from the Method drop-down list and click Execute. You should
see the Return value of DRAPHEAL.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
e. Select isUserInRole from l ฺ o
cthe Method
d edrop-down list and enter customer as the
i t u
maYouisshould
Value. Click Execute.
g S see the Return value of true.
f. Change the @ th and click Execute. The Return value should be false.
o Value to manager
ฺv i n
C (ac
d A
n o
Vi

g. Close the Business Components Browser.


h. If you would like to do so, you can run the Application Module again and test users that
are in different roles. Close the Business Components Browser after each test.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 19
Practice 20-9: Conditionally Displaying a Component Based on User
Role
When you tested the Web application and logged in as a customer, clicking the New Supplier
button produced an authorization error, which is not a good situation for a user who may have
no idea what this means. It would be better to prevent the customer from clicking this button. In
this practice, you use Expression Language so that the button does not appear when the
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

logged-in user does not have permission to run the task flow.
1. You know that customers do not have the view permission for the ManageSupplierFlow
task flow. Set a property on the button that invokes that task flow so that it does not appear
for customers.
a. Open BrowseSuppliers.jsff in the editor.
b. Click the New Supplier button and using the Expression Builder, set the Rendered
property to #{!securityContext.userInRole['fod_customer']}.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
2. Test the new functionality:
a. Run thein o@page andthlog in as a customer (DRAPHEAL). Click the Suppliers
Start
( a cฺv New Supplier button should not appear.
tab—the

d AC
Vi no

b. Run the application again and log in as a user in one of the other roles, such as
sking. The button should appear now.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 20
3. Although this works when you know the role that has access to the task flow, you do not
want to have to change the code if other roles are created or if grants for customers should
change. Set the button property so that the button does not appear for any user who does
not have permission to view the task flow.
a. Obtain the complete name of the task flow.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1) Open jazn-data.xml and click the Task Flows tab.


2) Click the Source tab at the bottom of the editor.
3) In the search field, enter ManageSupplier.
4) Copy (Ctrl + C) the entire task flow name (everything between the <name> and
</name> tags).

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
b. Open or switch to BrowseSuppliers.jsff ina noeditor.
the
eฺproperty to
c. a
Click the New Supplier button and set s i d
the Rendered
h t Gu and then paste the complete
)
m quotationn marks.
#{securityContext.taskflowViewable['']},
cosingle
task flow name betweenlฺthe
i u d e
g ma is St
o@ th
ฺv i n
(ac
4.AC
Ensure that the button appears if authentication security is not enabled. Instead of using a
n o d global security expression, write a security proxy bean to check the security. Name the
Vi bean FODSecurityBean.
a. Create a new Java class, accepting default values, named FODSecurityBean in the
oracle.storefront.ui.bean package with the following code: (You can copy the code
from SecurityBean.txt in the \files subdirectory.)
package oracle.storefront.ui.bean;

import oracle.adf.share.ADFContext;

public class FODSecurityBean {


public FODSecurityBean() {
}

public boolean isAuthorizationEnabled() {

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 21
return
(ADFContext.getCurrent().getSecurityContext().isAuthorizationEna
bled());
}
}
b. Register FODSecurityBean as a managed bean:
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1) Open adfc-config.xml and click the Overview tab.


2) Click the Managed Beans tab.
3) In the Managed Beans section of the page, click Add .
4) Set the following properties:
Property Value
Name FODSecurityBean
u se
Class oracle.storefront.ui.bean.FODSecurityBean
e to
n s
Scope request
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
5) On the BrowseSuppliers page
m ) nt Gchange the Rendered property of the
fragment,
New Supplier button toothe e
following expression:
i l ฺ c u d
g ma is St
#{FODSecurityBean.authorizationEnabled ?
th
securityContext.taskflowViewable['/WEB-
o@
v i n
INF/oracle/storefront/ui/flow/ManageSupplierFlow.xml#ManageSu
ฺpplierFlow']
( a c : true}

A C
n o d
Vi
c. Test the functionality as before, making sure that the button appears for clerks,
managers, or developers, and that it does not appear for customers.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 22
Practice 20-10: Modifying the Hard-Coded Username to Use the API
Previously you hard coded the username that is used to initialize the shopping cart. In this
practice, you replace the hard-coded name with a call to the method you just added.
1. Modify the TODO item in the base application module code to use the security API.
a. In the editor, open or switch to BaseApplicationModuleImpl.java.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

b. Click the pink box in the right margin of the code to go to the TODO item.
c. Replace the hard-coded username with a call to getUserName().

u se
e to
n s
i ce
d. Delete the commented TODO lines. b l el
e. Add a clause that sets the userPrincipal variable to the hard-coded string if fe ra
security is not implemented. Change the line: a n s
n - tr
to
String userPrincipal = getUserName();
a no eฺ
h a s uid
String userPrincipal;
m ) nt G
if
l ฺ o
c tude
i
ma is S
(ADFContext.getCurrent().getSecurityContext().isAuthorizationEna
bled())
@ g th
o
vin
userPrincipal = getUserName();

a c ฺ
else
C ( userPrincipal = "DRAPHEAL";
d A
i n o
V

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 23
2. Test the functionality.
a. Run FODShoppingCartAM and log in as DRAPHEAL.
b. In the Business Components Browser, double-click FODShoppingCartAM.
c. Select init from the Method drop-down list and click Execute.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n
e tos
d. l
Double-click ShoppingCart1 and click Cancel in the Bind Variables dialog i cbox
accept the values that were set in the init() method.
r a ble
e. The shopping cart for DRAPHEAL should be shown.
n s fe
n - tra
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi
3. Close the Business Components Browser when you have finished.
4. Disable security by running the Configure ADF Security Wizard (Application > Secure >
Configure ADF Security) and selecting the option to Remove ADF Security
Configuration. Click Finish.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 24
5. Run the application again to ensure that the button appears and that the shopping cart has
items. Notice that no login screen is required anymore.
You can probably see that security should be considered from the beginning, rather than
adding it at the end, so that the UI could be better designed to consider roles and their
access to task flows.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 25
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Lesson 20


Chapter 20 - Page 26
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anAppendix A
- r
on ฺ
Chaptern21
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 2
Practices for Appendix A
Practices Overview
In this practice, you use the database diagrammer to create a visual representation of the
database schema. You also create a new database component (a table) and create the DDL to
add it to the schema.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

This practice is optional and does not affect any of the other practices. You should work on it
only if you have extra time.
If you choose to work on this practice, start with a clean application by opening Storefront-
A.jws and editing the database information as described in step 4 of Practice 2-4.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 3
Practice A-1: Creating a Database Diagram with Existing Schema
Objects
In this practice, you examine the existing schema objects and use some of them in a new
database diagram.
1. In the Storefront application (the one that you created) in JDeveloper, examine the objects
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

in the FOD schema.


a. In the Application Navigator, expand the Application Resources section.
b. In the Application Resources section, expand the Connections and Database nodes.
You should see the FOD connection that you created in an earlier practice.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
c. Expand the FOD node to view
l ฺ o
c tude of database objects that the schema contains.
the types
2. Create a new database diagram i
a named S FODSchema and put it in the
g m s
@
oracle.fod.storefront.design
o t hi package.

c
from ฺ vtheincontext menu.
a. In the Application Navigator, right-click the StorefrontModel project and select New

C (a
b. In the New Gallery:
d A i) Expand the General node if it is not already expanded.
n o
Vi ii) Select Diagrams.
iii) In the Items panel, select Database Diagram.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 4
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
iv) Click OK.
h a s uid
c. In the Create Database Diagram)dialog box:
o m e n tG
i) Change the name of
a i lฺcyour diagram
t u d to FODSchema.
ii) Change the package
g S
m itosoracle.fod.storefront.design.
o@ t h
ฺv i n
C (ac
d A
n o
Vi

iii) Click OK. The blank diagram opens in the editor.


3. Depict the Orders and OrderItems table on the schema diagram.
a. In the Application Resources window, expand the Connections > Database > FOD
schema node, and then expand Tables.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 5
b. Use Ctrl-click to multiselect the Orders and Order_Items tables and drag them to the
diagram surface.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
c. In the Specify Location dialog box, changeathe
o database
noffline ฺ name to FodDB, and
s d e
then click OK to copy the database objects
)
and to place them on your diagram. ha t toGtheui new offline database in your project
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

d. The two tables are depicted on your diagram. Notice that the table icon has two
compartments. The top compartment displays the column names and their data types,
and the bottom compartment displays information about primary and foreign keys. Your

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 6
diagram should look something like the following screenshot.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d e. You can modify the column information in the diagram, although you should not modify
V i any of the table information at this time. To modify the column information, you can
click a column in the Orders table to select it, and then click again. You can modify
the name, data type, and size of the column in the diagram. Alternatively, you can
double-click the table itself to invoke the Edit Table dialog box, where you can make
more detailed modifications to columns and other table information. Do not modify any
columns for this practice.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 7
Practice A-2: Adding New Schema Objects
In this practice, you add a new schema object to the diagram. After adding new objects to the
diagram, you can synchronize the diagram with the database by generating directly to the
database, or you can first create a SQL script, and then run that against the database. In this
practice, you create a SQL script.
1. Add a new table to the diagram named Shippers, with a primary key named Shipper_Id
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

and a varchar2 column named Shipper_Name.


a. Ensure that the Component Palette is visible to the right of the diagram. If it is not,
select View > Component Palette.
b. In the Component Palette, ensure that Database is selected from the drop-down list at
the top. The list below it now displays the components suitable for adding to a schema
diagram.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i c. In the Component Palette, click Table and drag it to the schema diagram.
d. In the Specify Location dialog box, accept the default location of the FodDB offline
database and click OK.
e. In the name area at the top of the table icon, enter Shippers.

f. Select the table and resize it to make it easier to add columns.


g. Double-click the white space of the table diagram to invoke the Edit Table dialog box.
h. With the Columns node selected in the tree at the left of the Edit Table dialog box:
1) Click Add (plus icon) to add a new column, Shipper_Id:
2) Set the data type to Number.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 8
3) Set Precision to 10.
4) Make sure that Shipper_Id is a mandatory column by selecting the Cannot be
NULL check box.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
5) Similarly, add a Shipper_Name column, with the default values for data type and e to
size. This is not a mandatory column. n s
i ce
6) In the list at the left of the Edit Table dialog box, select Primary Key and set the
b l el
primary key as follows:
fe ra
a) Select SHIPPER_ID in the Available Columns list.
a n s
n - tr
7)
b) Click Add
a no eฺ
to shuttle SHIPPER_ID to the Selected Columns list.
Click OK. The diagram should look similar to this:
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
2. A C
Generate the DDL for adding the new table to the database, but do not actually add the
n o d table.
V i a. Right-click the SHIPPERS table in the diagram, and from the context menu, select
Synchronize with Database > Generate To > SQL Script. (You can also choose to
generate to FOD, which brings up the same dialog box with different default options
that you can change.)
b. In the Generate SQL from Database Objects Wizard:
1) Click Back until you are on the Specify Source page.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 9
2) On the Specify Source page, check the location of the objects to be generated (it
should be “Source from project”), and then click Next.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
3) Select the SQLScript option)on
asSpecify
hthe G u id page, and click Next.
Target
o m e n tSHIPPERS
4) The Object Picker page
i l ฺ c tud
should show in the Selected list. Click Next.
5) On the Choose a
mOperation Spage, select the Create option and click Next.
g i s
h page, change the name of the SQL file to
6) On the @
i n oSQL Script tOptions and click Next.
c ฺ v
CreateShippersTable.sql
(a
7) Click Finish to generate the script.

d AC
c. When the wizard is complete, the script file opens in the editor. Note the three tabs:
n o Source, SQL worksheet, and History. Examine the file contents.
Vi d. Do not run the script, but note that if you select a connection in the upper-right
corner, then you can right-click the script and select Run Script from the context menu,
or click Run Script .
e. Save your work.
f. When you have finished, close the script file and the database diagram. To close all
the open windows at once, right-click one of the tabs and select Close All.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix A


Chapter 21 - Page 10
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
f er a
Practicestfor s
anAppendix B
- r
on ฺ
Chaptern22
s a ide
) a
h t Gu
i l ฺ comtuden
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 1
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 2
Practices for Appendix B: Deploying ADF BC Applications
Practices Overview
In this practice, you create a deployment profile and configure deployment options for the
Storefront application that you have developed. You then configure a data source in the
stand-alone Oracle WebLogic Server, and you configure the application to use a data source.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Finally, you deploy the application to the stand-alone Oracle WebLogic Server, and you test the
deployment.
This practice is optional and does not affect any of the other practices. You should work on it
only if you have extra time.
If you choose to work on this practice, start with the completed application by opening
Storefront-B.jws and editing the database information as described in step 4 of
Practice 2-4.
u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 3
Practice B-1: Creating Deployment Profiles
In this practice, you create a new deployment profile for the application. It should specify a
Java EE Web Context Root of Storefront, and should specify the myWLS connection.
1. The default context root for the application is Storefront2-StorefrontUI-context-
root; because this context root becomes part of the URL to access the application, it is
better to use a shorter one. To set a new context root, you must create or edit a deployment
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

profile for the StorefrontUI project. Create a new deployment profile called
myStorefrontUI that specifies a context root of Storefront.
a. In the Application Navigator, select the StorefrontUI project, and then select File >
New.
b. In the New Gallery, select General > Deployment Profiles > WAR File.
c. In the Create Deployment Profile dialog box, enter a Deployment Profile Name of
myStorefrontUI and click OK.
u se
d. In the Edit WAR Deployment Profile Properties dialog box, select the Specify Java EE
Web Context Root option and enter a context root of Storefront. e to
n s
i ce
b l el
fe ra
a n s
n - tr
e. Click OK twice. a no eฺ
h a s ufor
2. Create a deployment profile named myStorefront
idthe application, specifying that it
m ) WAR file
n G the JAR file for the StorefrontModel
t and
o
should contain the myStorefrontUI e
project. a ilฺc Stud
g m menu
a. Invoke the Application is and select Application Properties.
@ t h
ฺ v ino
( ac
d AC
Vi no

b. In the Application Properties dialog box:


1) Select Deployment in the tree at the left.
Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 4
2) In the Deployment panel, click New.
c. In the Create Deployment Profile dialog box, set Archive Type to EAR File and the
name to myStorefront, and then click OK.
d. In the Edit EAR Deployment Profile Properties dialog box:
1) Select Application Assembly in the tree at the left.
2) In the Application Assembly panel, select the myStorefrontUI and
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

StorefrontModelArchive check boxes, and then click OK twice.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 5
Practice B-2: Using a WebLogic Server Data Source
A stand-alone Oracle WebLogic Server has already been created for you and configured to run
ADF applications. In this practice, you use the Oracle WebLogic Server Administration Console
to create a data source that the deployed application can use. You then configure the
application to use a JDBC DataSource connection type rather than the JDBC URL connection
type that it has been using by default.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

1. Set up a data source named FODLocal in the basic_domain domain of the stand-alone
Oracle WebLogic Server, setting the JNDI name to jdbc/FODDS. Set other properties so
that it connects to the same schema that you have been using.
a. From the Windows Start menu, select Programs > Oracle Fusion Middleware > User
Projects > MyWLS_domain > Admin Server Console. The console application
deploys and then runs.
Note: If the Administration Server Console does not run, make sure that the WebLogic
Server is running. If it is not running, invoke the same menu except select as the final u se
item Start Admin Server for WebLogic Server Domain. After the server has started,
e to
you can minimize the startWebLogic command window. n s
i ce
b. Log in to the Administration Server Console with the username of weblogic and the
password of weblogic. b l el
fe ra
c. In the Domain Structure menu at the left of the window, expand the Services and
a n s
n - tr
JDBC nodes, and then click the Data Sources node.

a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
d. On the “Summary of JDBC Data Sources” page, click New.
e. In the “Create a New JDBC Data Source” Wizard, set the following properties:
Property Value
Name FODLocal
JNDI Name jdbc/FODDS
Database Type Oracle
Database Driver Oracle's Driver (Thin)
Versions:9.0.1,9.2.0,10,11
Database Name XE
Host Name localhost

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 6
Port 1521
Database User <your schema>, such as fod01
Name
Password fusion
f. On the next page of the wizard, click Test Configuration. If the test is successful, click
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

Next. (Do not click Finish.)


g. On the next page of the wizard, select the AdminServer check box as a target to
deploy the data source, and then click Finish. You should receive a message that the
changes are activated, and your new data source should be listed.
2. Configure the application modules to use the data source, rather than the JDBC URL
connection that you have been using.
a. In the JDeveloper Application Navigator, right-click the FODCategoryAM application
module and select Configurations. u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
b. In the Manage Configurations dialog box:
1) Select FODCategoryAMLocal and click Copy.
2) Select the new FODCategoryAMLocal1 configuration, and then click Edit.
c. In the Edit Business Components Configuration dialog box, set the following properties:
Property Value
Configuration FODCategoryAMWeb (change Local1 in the name to
Name Web)
Connection Type JDBC DataSource
Datasource Name Java:comp/env/jdbc/FODDS
d. Click OK twice.
e. Perform steps a through d for all the application modules.
3. Configure the data bindings to use the data source.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 7
a. In the Application Navigator, select DataBindings.cpx in the StorefrontUI project.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
b. In the Structure window:
i ce
1) Expand DataBindings > dataControlUsages.
b l el
2) Select each application module data control usage, and in the Property Inspector,
fe ra
n s
set its Configuration to be the Web configuration that you just defined, such as
a
FODProductAMWeb.
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
3) Repeat steps 1 and 2 for all five application server data control usages.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 8
Practice B-3: Creating an Application Server Connection
To deploy to an application server from within JDeveloper, you must first create a connection to
it.
1. Create an application server connection to the stand-alone WebLogic Server. Name the
connection myWLS, with a username of weblogic and a password of weblogic. Use a
Port of 7001 and a WLS Domain named base_domain.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. From the JDeveloper menu, select View > Application Server Navigator.
b. Right-click the Application Servers node and select New Application Server.
c. In the Create Application Server Connection Wizard, enter the following settings,
leaving others at their default values:
Property Value
Connection Name myWLS
u se
Password weblogic
e to
Deploy Password Checkbox selected n s
i ce
Port 7001
b l el
WLS Domain myWLS_domain fe ra
a n s
d.
n - tr
On the last page of the wizard, click Test, and then click Finish if the connection is
successful.
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i
e. The connection appears in the Application Server Navigator. Expand the myWLS and
deployments nodes so that you can see what is already deployed.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 9
Practice B-4: Deploying the Application from JDeveloper
You have prepared the application and the OracleWebLogic Server for deployment. In this
practice, you use JDeveloper to deploy the application to the application server.
1. Using the deployment profile that you defined in this set of practices, deploy the Storefront
application to the stand-alone WebLogic Server.
a. Invoke the Application menu and select Deploy > myStorefront > to > myWLS.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a noIt may
The log window displays deployment messages.
e ฺ take a few minutes to finish the
s
ha t the
deployment; wait until the window displays i d
umessage that the deployment is
finished. ) G
i l ฺ comtuden
g ma is S
o@ th
ฺv i n
C (ac
d A
n o
Vi

b. In the Application Server Navigator, click Refresh to see the myStorefront deployment.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 10
2. Test the deployment.
a. In a browser, enter the URL
http://127.0.0.1:7001/Storefront/faces/FODShoppingDashboard.
b. Ensure that data appears properly, that the New Supplier button is shown on the
BrowseSuppliers page, and that there are items in the shopping cart.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

c. When you have finished, close the browser and undeploy the application as follows:
1) On the Application Server Navigator, click Refresh .
2) Right-click the myStorefront deployment and select Undeploy.

u se
e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
A C
n o d
V i

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 11
Practice B-5: Deploying the Application from the WebLogic Server
Administration Console
In this practice, you use the WebLogic Server Administration Console to deploy the application.
1. Use JDeveloper to create a deployable EAR file, making note of the directory where the
EAR file is created.
Unauthorized reproduction or distribution prohibitedฺ Copyright© 2011, Oracle and/or its affiliatesฺ

a. From the Application Navigator, invoke the Application menu.


b. Select Deploy > myStorefront > to EAR file.
c. In the log file, note the location of the EAR file.
2. Use the Oracle WebLogic Server Administration Console to deploy the application.
a. Invoke the Administration Console, or switch to it if it is already open.
b. From the Domain Structure menu at the left, select Deployments.
c. In the Deployments panel, click Install.
d. By clicking through the displayed directories, locate the myStorefront.ear file in the u se
directory where it was created and select it, and then click Next. e to
n s
i ce
b l el
fe ra
a n s
n - tr
a no eฺ
h a s uid
m ) nt G
l ฺ o
c tude
i
g ma is S
o @ th
c ฺ vin
( a
C
A Select the Install this deployment as an application option and click Next.
e.
n o d f. Select the Copy this application onto every target for me option and click Next.
V i
g. Select the Yes, take me to the deployment's configuration screen option and click
Finish.
h. Review the configuration options, but do not change them. Click Save.
i. Click Deployments on the menu. You should see that the application is deployed.
3. Test the deployment as you did above.

Copyright © 2010, Oracle and/or its affiliates. All rights reserved.

Practices for Appendix B


Chapter 22 - Page 12

You might also like