You are on page 1of 386

THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY.

COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

D68162
July 2010
Edition 2.0
D53979GC20
ADF I
Activity Guide
Oracle Fusion Middleware
11g: Build Applications with

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

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:

Oracle University and Egabi Solutions use only


U.S. GOVERNMENT RIGHTS
The U.S. Governments rights to use, modify, reproduce, release, perform, display, or disclose these training materials are restricted
by the terms of the applicable Oracle license agreement and/or the applicable U.S. Government contract.

Trademark Notice

Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.

Authors
Kate Heap, Patrice Daux

Technical Contributors and Reviewers


Joe Greenwald, Glenn Maslen

This book was published using: Oracle Tutor


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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


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

Oracle University and Egabi Solutions use only


Practices for Lesson 3: Building a Data Model with ADF Business Components ..........................................3-3
Practice 3-1: Creating Default Business Components ...................................................................................3-4
Practice 3-2: Testing the Business Model ......................................................................................................3-8

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


Practices for Lesson 4: Querying and Persisting Data ...................................................................................4-3
Practice 4-1: Creating Read-Only View Objects.............................................................................................4-4
Practice 4-2: Creating Multiple Read-Only View Objects at Once ..................................................................4-7
Practice 4-3: Creating Entity Objects Based on Database Views...................................................................4-9
Practice 4-4: Creating Multiple Entity Objects at Once...................................................................................4-11
Practice 4-5: Creating Associations ...............................................................................................................4-12
Practice 4-6: Creating Updatable View Objects .............................................................................................4-14
Practice 4-7: Refactoring Associations and Links ..........................................................................................4-17

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


Practices for Lesson 5: Exposing Data to Clients...........................................................................................5-3
Practice 5-1: Creating an Application Module to Display Categories .............................................................5-4
Practice 5-2: Creating an Application Module to Display the Shopping Cart ..................................................5-5

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


Practices for Lesson 6: Declaratively Customizing Data Services .................................................................6-3
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


Practices for Lesson 10 ...................................................................................................................................10-1
Practices for Lesson 10: Understanding UI Technologies ..............................................................................10-3

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


Practices for Lesson 11: Binding UI Components to Data .............................................................................11-3
Practice 11-1: Creating Databound Pages .....................................................................................................11-4
Practice 11-2: Examining the Page's Data Bindings ......................................................................................11-8
Practice 11-3: Adding an Additional Detail Table ...........................................................................................11-11
Practice 11-4: Renaming a Page ...................................................................................................................11-13

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


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 ................................................................................................12-10
Practice 12-3: Extracting Part of a Task Flow ................................................................................................12-16

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


Practices for Lesson 13: Adding Functionality to Pages ................................................................................13-3
Practice 13-1: Creating a Table with Row Selection ......................................................................................13-4
Practice 13-2: Creating a Search Page ..........................................................................................................13-10
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


Practice 17-2: Using Parameters for Dynamic Breadcrumbs .........................................................................17-11
Practice 17-3: Implementing the Add to Cart Functionality ............................................................................17-13
Practice 17-4: Implementing Create Supplier Functionality (Optional) ...........................................................17-17

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


Practices for Lesson 18: Responding to Application Events ..........................................................................18-3
Practice 18-1: Defining Task Flow Parameters ..............................................................................................18-4
Practice 18-2: Creating a Helper Method to Evaluate EL ...............................................................................18-5
Practice 18-3: Creating the Producer (Payload) Method ................................................................................18-9
Practice 18-4: Initiating the Contextual Event ................................................................................................18-12
Practice 18-5: Creating the Consumer (Handler) Method ..............................................................................18-14
Practice 18-6: Mapping the Contextual Event ................................................................................................18-16
Practice 18-7: Passing Values Through Region Parameters .........................................................................18-19
Practice 18-8: Modifying the JSF Life Cycle (Optional Exercise) ...................................................................18-21

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


Practices for Lesson 19: Implementing Transactional Capabilities ................................................................19-3
Practice 19-1: Saving the Shopping Cart .......................................................................................................19-4
Practice 19-2: Updating, Deleting, and Displaying Details of Shopping Cart Items ........................................19-5
Practice 19-3: Controlling Transactions in the CheckoutFlow ........................................................................19-12
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
Practice B-5: Deploying the Application from the WebLogic Server Administration Console .........................22-12

Oracle University and Egabi Solutions use only

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

Oracle Fusion Middleware 11g: Build Applications with ADF I Table of Contents
iv
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 1


Chapter 1 - Page 1
Chapter 1

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


Practices for Lesson 1

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 1


Chapter 1 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 1: Introduction to Oracle Fusion and Oracle


ADF
There is no practice for this lesson.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 1


Chapter 1 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 1


Chapter 1 - Page 4
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 2


Chapter 2 - Page 1
Chapter 2

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


Practices for Lesson 2

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 2


Chapter 2 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
JDeveloper application, project, and database connection. You then view the course application
in a browser and identify the functionality of the pages.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 2


Chapter 2 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.


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.)

Oracle University and Egabi Solutions use only


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,
respectively, and should be created in the entity, uiview, and module packages,
respectively.
a. From the JDeveloper menu, select Tools > Preferences > Business Components >
Object Naming.
b. In the dialog box, set suffixes as follows:
Entity EO
View Object VO
Application Module AM

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d.

Practices for Lesson 2


Click OK.

Chapter 2 - Page 5
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


4) Click Next.
a. On the Name your project page of the wizard:
1) Enter StorefrontModel as the project name.
2) On the Project Technologies tab, shuttle ADF Business Components and
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 2


Chapter 2 - Page 7
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


Components check box.

d. Click Create a new database connection to the right of the Connection field.
e. In the Create Database Connection dialog box:
1) Supply the information in the table below.
Connection Name FOD
Connection Type Oracle (JDBC)
Username fod (or follow the instructions given by
your instructor if you are using a shared
database)
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. Click OK to dismiss the Create Database Connection dialog box and return to the

Oracle University and Egabi Solutions use only


Business Components page of the Project Properties dialog box.
g. Click OK to set the project properties and dismiss the Project Properties dialog box.

h. Click Save All to save your work. You should get into the habit of frequently
saving your work.

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

Practices for Lesson 2


Chapter 2 - Page 9
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


OR if there is an open application, you can invoke the drop-down application list by
clicking the down arrow at the right of the application name in the Application
Navigator, and then selecting Open Application

OR click Open on the JDeveloper menu toolbar

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 courses \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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


application, execute the necessary steps to perform the operation.
2. Open the main task flow for the application, which is adfc-config.
a. The application contains two projects that are displayed on the first level of the
applications hierarchy. Expand the StorefrontUI node.
b. In the StorefrontUI project, expand the Web Content and Page Flows nodes.
c. Double-click adfc-config to open it in the editor.
3. When a task flow opens in the editor, you will see a Thumbnail tab to the left of the editor,
below the Application Navigator. Click the Thumbnail tab, and then drag the viewport
rectangle so that the view activities are visible in the editor.

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

Practices for Lesson 2


Chapter 2 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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,
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.

Oracle University and Egabi Solutions use only


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
a table of categories and descriptions at the right. In the tree, expand the Media
category and click the Music subcategory.

b. A list of Music products appears in the right panel. Note that there are breadcrumbs
along the top of the table that enable you to navigate to the Media subcategory, or to
the main-level list of categories if you click Store. For now, click the name of one of
the products.

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

Practices for Lesson 2


Chapter 2 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


d. On the Search page, enter Pla in the ProductName field and click Search. A list of
products beginning with Pla is returned.

e. Click the Playstation Portable link to display details about this product.

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

Practices for Lesson 2


Chapter 2 - Page 13
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. Click Add Item to Cart to add the Playstation Portable to the shopping cart and display
the cart.

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.

Oracle University and Egabi Solutions use only


h. With the Playstation Portable selected, click Delete to remove it from your cart.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


l. The second page of the checkout process displays the billing information. Navigate to
the next page either by clicking Next or by clicking the Confirmation train stop at the
top of the panel.

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

Practices for Lesson 2


Chapter 2 - Page 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

m. The final page of the checkout process displays all the informationshipping, 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
and the billing department, and sending an email confirmation to the customer. This
functionality is outside the scope of the course application.

Oracle University and Egabi Solutions use only


6. Test the functionality of managing suppliers.
a. Click the Suppliers tab in the left panel of the page.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

c. The New Supplier page initializes. Enter any supplier name and select a supplier status
from the drop-down list, and then click Save.

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.

Oracle University and Egabi Solutions use only


e. Click the SupplierId of one of the suppliers in the list.
f. On the Update Supplier page, change the Status of the supplier and click Save.

g. The supplier is shown in the list with the updated status.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) In the Run Manager window, select Storefront-CompletedApp (Running on


IntegratedWebLogicServer), and then click the red square to undeploy.

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


menu toolbar, and then select the application to undeploy.

Oracle University and Egabi Solutions use only


j. The application is undeployed when the log window displays the message: [Application
Storefront-CompletedApp stopped and undeployed from Server Instance Instance
IntegratedWebLogicServer].
7. Close the Storefront-CompletedApp application. You should continue to work in the
Storefront application that you created.
a. Invoke the application menu by clicking the right-most down arrow at the top of the
Application Navigator.
b. Select Close Application from the IDE.

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

Practices for Lesson 2


Chapter 2 - Page 18
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 3


Chapter 3 - Page 1
Chapter 3

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


Practices for Lesson 3

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 3


Chapter 3 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


information as described in step 4 of Practice 2-4.

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

Practices for Lesson 3


Chapter 3 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
b. Select Business Tier > ADF Business Components in the Categories list.
c. Select Business Components from Tables in the Items list.
d. Click OK.

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Select ORDERS in the Selected pane and change the Entity Name to OrderEO
(instead of OrdersEO).

Oracle University and Egabi Solutions use only


f. Similarly, change the Entity Name of OrderItemsEO to OrderItemEO.
g. Set the Name Filter to % and click Query to show all the available tables. If you were
creating several more entity objects, you could multiselect any tables for which you
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
change the default name of the entity object.
h. Click Next.
3. Continuing in the Create Business Components from Tables Wizard, create the following
updatable view objects (do not create any read-only view objects at this time):
VO Based on
ShoppingCartVO OrderEO
ShoppingCartItemVO OrderItemEO
a. On the Updatable View Objects page of the wizard, ensure that the package name is
oracle.fod.storefront.uiview.

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 customers shopping cart.

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

Practices for Lesson 3


Chapter 3 - Page 5
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Similarly, rename OrderItemVO to ShoppingCartItemVO.

Oracle University and Egabi Solutions use only


f. Click Next.
g. The next page is for creating read-only view objects. These are based on SQL queries
rather than on entity objects. For now, you will not create read-only VOs, so click Next.
4. Continuing in the Create Business Components from Tables Wizard, create an application
module to provide access to your components. You will later create application modules
that are customized for your application, but you can use a default application module for
testing your components. Create an application module named TestAM in the
oracle.fod.storefront.test package.
a. On the Application Module page of the wizard, ensure that the Application Module
check box is selected.
b. To separate this test application module from those that you customize for the
Storefront application, change the package name to
oracle.fod.storefront.test.
c. Change the application module name to TestAM.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:

Oracle University and Egabi Solutions use only


d. Click Finish to create the business components. This may take a few moments.
e. Click Save All to save your work.
f. The StorefrontModel project in the Applications Navigator should look like this:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


Components Browser.
a. In the Application Navigator, right-click the application module (TestAM) in the
oracle.fod.storefront.test package and select Run.
b. The Business Components Browser may take a few minutes to appear, and it may
appear behind other windows. You can click its icon on the taskbar to display it.
The Browser should initially look similar to the following (the objects can be in a
different order):

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


d. In the top portion of the page, click Move to the next row to navigate through rows
in the Orders view. Note that the order items change as you move to a new order.
e. Open the other views and examine the contents as you choose.
f. When you have finished, close the Business Components Browser.

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

Practices for Lesson 3


Chapter 3 - Page 9
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 3


Chapter 3 - Page 10
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 4


Chapter 4 - Page 1
Chapter 4

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


Practices for Lesson 4

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 4


Chapter 4 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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-04.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.

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

Practices for Lesson 4


Chapter 4 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
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

Oracle University and Egabi Solutions use only


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
course.)
SELECT
LOOKUP_CODES.LOOKUP_TYPE LOOKUP_TYPE,
LOOKUP_CODES.LOOKUP_CODE LOOKUP_CODE,
LOOKUP_CODES.MEANING MEANING,
LOOKUP_CODES.DESCRIPTION DESCRIPTION,
LOOKUP_CODES.LANGUAGE LANGUAGE
FROM
LOOKUP_CODES
WHERE
LOOKUP_CODES.LANGUAGE = SYS_CONTEXT('USERENV', 'LANG') AND
LOOKUP_CODES.LOOKUP_TYPE = :BindLookupType
a. In the Application Navigator, right-click the StorefrontModel project and select New
from the context menu.
b. In the New Gallery, expand the Business Tier node in the Categories list and select
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) Specify that the view object should have Read-only access through SQL query.

Oracle University and Egabi Solutions use only


3) Click Next.
d. On the Query page of the wizard:
1) Enter the query statement shown in step 1. (You can copy from
LookupCodes.txt, or click Query Builder to build the query if desired, but make
sure that the finished query is as shown above.)
2) Click Test to verify that the query is valid.
3) Click Next.
e. On the Bind Variables page of the wizard:
1) Click New.
2) On the Variable tab in the lower section of the page, enter BindLookupType as
the name for the variable, leaving all other values at their defaults.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
similar to the following screenshot:

Oracle University and Egabi Solutions use only


g. Save your work.
2. Test the query:
a. Run TestAM as you did previously.
b. In the Business Components Browser, double-click the LookupCodeV1 node.
c. In the Bind Variables dialog box, enter a Value such as SHIPPING_CLASS_CODE and
click OK.
d. Navigate through the rows to see all the payment type codes. Note that all fields are
disabled, because this view object is read-only.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
Query Table or View VO
COUNTRY_CODES CountryVVO
PERSONS CustomerVVO
PAYMENT_OPTIONS (optional) PaymentOptionVVO
PRODUCTS (optional) ProductVVO

Oracle University and Egabi Solutions use only


WAREHOUSES (optional) WarehouseVVO
Note: Creating all of these view objects is optional. You can create them all if you
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.
a. As you did in Practice 3-1, step (1), invoke the Create Business Components from
Tables Wizard.
b. Click Next to navigate to the Read-Only View Objects page of the wizard:
1) Set the package name to oracle.fod.storefront.view.
2) Select your schema (FOD) from the drop-down list.
3) Use the Name Filter, or simply click Query, to find and select the tables and views
shown above and modify the name in each case as before (note the VVO suffix).

4) Click Next.

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

Practices for Lesson 4


Chapter 4 - Page 7
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:

Oracle University and Egabi Solutions use only

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

Practices for Lesson 4


Chapter 4 - Page 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
designate a primary key for such EOs. You can do that with the Create Entity Object Wizard.
In this practice, you create several database viewbased 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

Oracle University and Egabi Solutions use only


an even easier way to invoke the wizards:
1) In the Application Navigator, expand the StorefrontModel project.
2) Expand the Application Sources and oracle.fod.storefront nodes.
3) Right-click the entity node and select New Entity Object.

b. On the Name page of the Create Entity Object Wizard:


1) Ensure that oracle.fod.storefront.entity is the package name.
2) Enter ProductCategoryEO as the entity object name.
3) Ensure that the Database Schema Object option is selected and that the
database schema is FOD.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


2. Optional step (If you choose not to create these objects, you must begin the
practices for the next lesson by opening the starter application.)
Similarly, create the following entity objects that are based on database views:
EO Based on Database View Primary Key
PersonInformationEO PERSON_INFORMATION CustomerId
ProductEO PRODUCTS ProductId

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

Practices for Lesson 4


Chapter 4 - Page 10
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
EO Based on
AddressEO ADDRESSES
AddressUsageEO ADDRESS_USAGES
CountryEO COUNTRY_CODES

Oracle University and Egabi Solutions use only


LookupCodeEO LOOKUP_CODES
PaymentOptionEO PAYMENT_OPTIONS
SupplierEO SUPPLIERS
WarehouseEO WAREHOUSES
WarehouseStockLevelEO WAREHOUSE_STOCK_LEVELS
Note: Creating all of these entity objects is optional. You can create them all if you
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.
a. In the Application Navigator, right-click the oracle.fod.storefront.entity package, and
select New Business Components from Tables.
b. On the Entity Objects page of the Business Components from Tables Wizard, check
whether the package name is oracle.fod.storefront.entity and the schema is
FOD. Click Query.
c. As you did in an earlier practice, Ctrl-click to select multiple tables for which to create
entity objects, and rename the entity objects, according to the table shown above.
d. Click Finish to create the entity objects.

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

Practices for Lesson 4


Chapter 4 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


2) Enter a name of ProductCategoriesSubProductCategoriesAssoc.
3) Click Next.
c. On the Entity Objects page of the wizard:
1) Expand ProductCategoryEO in the Select Source Attribute list and select the
CategoryId attribute.
2) Expand ProductCategoryEO in the Select Destination Attribute list and select the
ParentCategoryId attribute.
3) Click Add, and then click Next.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.)

Oracle University and Egabi Solutions use only


In a similar manner, create an association named OrderItemsProductsAssoc between
the ProductId fields of the OrderItemEO and ProductEO entity objects. The application
needs to access the product for a particular order item, but never needs to access order
items that pertain to a particular product, so expose accessors only in the destination
entity for this association. (Deselect the check box in the Source Accessor section.)
4. Save your work. Including the optional steps, the entity package in the Application
Navigator should now look like this:

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

Practices for Lesson 4


Chapter 4 - Page 13
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


package and select New View Object from the context menu.
b. On the Name page of the Create View Object Wizard:
1) Ensure that the package is oracle.fod.storefront.uiview.
2) Enter RootCategoryVO as the view object name.
3) Select the Updatable access through entity objects option.
4) Click Next.
c. On the Entity Objects page:
1) Expand the oracle.fod.storefront.entity package node.
2) Shuttle ProductCategoryEO into the Selected pane.
3) Click Next.
d. On the Attributes page:

1) Click Add All to shuttle all attributes into the Selected pane.
2) Click Next.
e. On the Attribute Settings page, click Next.

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

Practices for Lesson 4


Chapter 4 - Page 14
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


3) Click Next.
g. Navigate through the subsequent pages until you reach the Application Module page:
1) Add the view object to the TestAM application module as you have been doing.
2) Click Finish to create the updatable view object.
h. Similarly, create the SubCategoryVO view object based on the same
ProductCategoryEO entity object, with all attributes.
1) Use the following WHERE clause:
ProductCategoryEO.PARENT_CATEGORY_ID IS NOT NULL
Place the view object in your TestAM application module.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Click Add.

Oracle University and Egabi Solutions use only


f. Click Next several times until you reach the Application Module page. Select the
Application Module check box and browse to select the TestAM application module
in the oracle.fod.storefront.test package. Click Finish to create the view link.
3. Optional step (If you choose not to create this object, you must begin the practices
for the next lesson by opening the starter application.)
Similarly, create one more updatable view object named SupplierVO in the
oracle.fod.storefront.uiview package. Base it on SupplierEO, including all
attributes. Do not include a WHERE clause. Add the view object to the TestAM application
module.
4. Save your work, and then test the view objects and view link that you just created.
a. Run TestAM as before.
b. Check whether the RootCategory1 view object instance displays the data you expect
(only those categories without a ParentCategoryId should display).
c. Check whether the SubCategory1 view object instance displays the data you expect
(only those categories with a ParentCategoryId).
d. Test that RootCategoriesSubCategoriesLink displays the master-detail relationship
between root categories and subcategories, similar to the following:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. In the Move Business Components dialog box, enter the Package name of
oracle.fod.storefront.assoc and click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. JDeveloper creates the assoc package and moves the associations into it. This may
take several minutes.

Oracle University and Egabi Solutions use only


2. In a similar manner, move all view links into the oracle.fod.storefront.link
package. Refactor links in both the uiview and the view packages.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 5


Chapter 5 - Page 1
Chapter 5

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


Practices for Lesson 5

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 5


Chapter 5 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
managing a customers 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,

Oracle University and Egabi Solutions use only


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-05.jws and edit the database information as described in step 4 of Practice 2-4.

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

Practices for Lesson 5


Chapter 5 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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 University and Egabi Solutions use only


oracle.fod.storefront.uiview and RootCategoryVO.
d. Select RootCategoryVO and shuttle it to the Data Model.
e. With RootCategoryVO1 selected in the Data Model panel, shuttle SubCategoryVO
via RootCategoriesSubCategoriesLink to the Data Model.
f. Click Finish to create the application module.
g. Save your work.
2. Test the application module and then close the Business Components Browser when you
have finished.

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

Practices for Lesson 5


Chapter 5 - Page 4
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practice 5-2: Creating an Application Module to Display the Shopping


Cart
In this practice, you create the application module to display a customers 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
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.

Oracle University and Egabi Solutions use only


d. Select ShoppingCartVO and shuttle it to the Data Model.
e. With ShoppingCartVO1 selected in the DataModel, shuttle ShoppingCartItemVO via
OrderItemsOrdersFkLink to the Data Model.
f. Click Finish to create the application module.
g. Save your work.
2. Test the application module and then close the Business Components Browser when you
have finished.
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.

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

Practices for Lesson 5


Chapter 5 - Page 5
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 5


Chapter 5 - Page 6
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 6


Chapter 6 - Page 1
Chapter 6

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


Practices for Lesson 6

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 6


Chapter 6 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 6


Chapter 6 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.)

Oracle University and Egabi Solutions use only


d. In the Edit Attribute dialog box, select Control Hints in the list at the left.
e. Set the Format Type to Currency.
f. Set the Label Text to Order Total by using a resource bundle (for translatable text),
as follows:
1) Click the ellipsis to the right of the Label Text field.
2) In the Select Text Resource dialog box:
a) In the Display Value field, enter Order Total. This automatically populates
the Key field, but you could change the Key value if desired. However, you
can leave it at the default for this attribute.
b) Enter the following in the Description field: Label for OrderTotal
attribute.
c) Click the Save and Select button.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


Note: Whether or not the instructions specifically direct you to do so, you can use
a text resource in a resource bundle for any translatable text throughout these
practices, as you would need to do for a real application. However, in the interest
of time, you may choose to simply enter the hard-coded text.
h. Click OK to dismiss the attribute editor for OrderTotal.
i. Optional step: Using a resource bundle, enter appropriate Label Text and Tool tip
Text for OrderDate and OrderShippedDate. For example:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d.

Practices for Lesson 6


Chapter 6 - Page 6
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Close the Business Components Browser when you have finished.

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
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

Oracle University and Egabi Solutions use only


INTO :NEW.SUPPLIER_ID
FROM DUAL;
END IF;
END;
This ensures that when a new row is committed with a null primary key, the value from the
database sequence populates the primary key. When you use a database trigger to populate
the primary key, there are few gaps in the sequence of the primary keys, because the database
sequence does not get used until the row is committed.
On the Business Components model side, all that is required is to populate the value
temporarily, so that the NOT NULL primary key can be committed. That is what happens when
you declaratively set the column to use a database sequence, as you do in this practice.
1. Set SupplierEO to use a database sequence at commit time for its primary key. There is
already a database trigger defined that populates the primary key from a database
sequence if it is null.
a. In the Application Navigator, double-click SupplierEO to open it in the editor.
b. Click the Attributes tab.
c. Select the SupplierId attribute and click Edit .
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. Make sure that the attribute has the following properties:

Oracle University and Egabi Solutions use only


Value 0
While New Selected
Persistent Selected
Primary Key Selected
Queryable Selected
Insert Selected

g. Click OK.

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

Practices for Lesson 6


Chapter 6 - Page 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


b. Click the Attributes tab.
c. Select the CreationDate attribute and click Edit .
d. In the Edit Attribute dialog box, select Entity Attribute in the list at the left.
e. Select the History Column check box and select created on from the drop-down list.
f. Click OK.
g. Similarly, edit the following attributes by selecting the History Column check box and
choosing the following values from the drop-down list:

Attribute Name History Column value


LastUpdateDate modified on
ObjectVersionId version number

h. To populate the history columns for created by and modified by, there must be a
logged-in user. You later designate these attributes as history columns, but to test with
the Business Components Tester with no logged-in user, you simply give these
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


e. Enter a SupplierName, such as ABC Plumbing, and a SupplierStatus, such as
ACTIVE.

f. Click Save .
g. Ensure that the SupplierId value is populated from the database sequence.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


f. Click Delete in the lower and then in the upper sections of the panel to delete the
new rows without committing them.
g. Close the Business Components Browser when you have finished.

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

Practices for Lesson 6


Chapter 6 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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 .

Oracle University and Egabi Solutions use only


d. In the Create View Criteria dialog box, click the Criteria Definition tab and click the
Add Item button.

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

Practices for Lesson 6


Chapter 6 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
Operator Equal to
Operand Bind Variable
Parameter Click New and define a variable named
PersonId of type Number.
Validation Optional

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. In the Bind Variables dialog box, enter a value of 110 and click OK.

Oracle University and Egabi Solutions use only


f. The payment options for customer 110 should be displayed.
g. You can test with other values if you would like to do so. Some other valid values are
114, 117, and 119.
h. Close the Business Components Browser when you have finished testing.

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

Practices for Lesson 6


Chapter 6 - Page 14
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


ShoppingCartVO view object.
a. In the Application Navigator, in the oracle.fod.storefront.uiview package,
double-click the ShoppingCartVO view object to open it in the editor.
b. Click the Entity Objects tab to the left of the editor.
c. Expand oracle.fod.storefront.entity and shuttle PersonEO to the Selected list.
d. Select PersonEO in the Selected list. Ensure that the Association is set to
OrdersPersonsFkAssoc.Person and that the Join Type is set to inner join. Ensure
that the Updatable check box is not selected, and that the Reference check box is
selected.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) In the Attributes Editor, select PersonEO in the Available list and shuttle it to the
Selected listthis adds all of its attributes.

Oracle University and Egabi Solutions use only


3) Click OK.
2. Optional step: (If you choose not to create these objects, you must begin the
practices for the next lesson by opening the starter application.)
Similarly, add reference entities and attributes to ShoppingCartItemVO as follows:
Entity Object Attributes
ProductEO ProductId
ProductName
Description
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


3. Optional step: (Perform this step only if you added history columns to the
ShoppingCartItemEO entity.):
Delete the history attributes from ShoppingCartItemVO. You do not need these mandatory
attributes in the view object because you have set their values in the entity object.
a. If it is not already open, double-click the ShoppingCartItemVO view object in the
oracle.fod.storefront.uiview package of the Application Navigator to open it in the
editor.
b. Click the Attributes tab and delete the following attributes: CreatedBy,
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


e. Select ProductVVO and shuttle it to the View Accessors list, and then click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d. Expand the List of Values section in the editor and click Add list of values .

Oracle University and Egabi Solutions use only


e. In the List of Values dialog box:
1) On the Configuration tab:
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


3) Click OK.

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

Practices for Lesson 6


Chapter 6 - Page 20
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


c. Change the initial product to some other product.
d. Double-click OrderItemsOrdersFkLink1 under ShoppingCart1.
e. Query for the same order that appears in the ShoppingCartItem1 window (order 1034
in the example shown above). The corresponding shopping cart item should show the
change that you made in the other window. View objects that display the same data
remain in sync throughout the application.

f. Close the Business Components Browser.

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

Practices for Lesson 6


Chapter 6 - Page 21
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 6


Chapter 6 - Page 22
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 7


Chapter 7 - Page 1
Chapter 7

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


Practices for Lesson 7

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 7


Chapter 7 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 7


Chapter 7 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


d. Save your work.
2. Generate the Entity Object Java class for OrderEO and add the following method for
adding an item to the cart: (You can copy the code from the addItemToOrder.txt file in
the \files subdirectory of your \labs directory.)
a. Similarly, generate the entity object class for OrderEO.
b. Click the Entity Object Class link to open OrderEOImpl.java in the editor.

c. Note that the Structure window shows the methods that are included in the class. (If
the Structure window is not visiblethat is, the default location is at the lower left of the
IDEthen 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

navigate to it in the editor.

Oracle University and Egabi Solutions use only


d. In the editor, scroll to the bottom of the file and just above the closing right brace, add
the code shown below. You can copy the code from the addItemToOrder.txt file in
the \files subdirectory of your \labs directory.
/**
* Add an item to the order. Typically used to add items to the
shopping cart.
*
* @param productId
*/
public void addItemToOrder(Number productId) {
if (productId == null) {
System.err.println("NO PRODUCT ID!!!");
throw new NullPointerException();
}

RowIterator orderItems = getOrderItem();


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

qty = new Number(1);


else
qty = qty.add(1);
row.setQuantity(qty);
} else {
OrderItemEOImpl newItem =
(OrderItemEOImpl)orderItems.createRow();
EntityDefImpl productEODef =
EntityDefImpl.findDefObject("oracle.fod.storefront.entity.Produc
tEO");

EntityImpl productEO =

Oracle University and Egabi Solutions use only


productEODef.findByPrimaryKey(getDBTransaction(), new Key(new
Object[] { productId }));
Number unitPrice =
(Number)productEO.getAttribute("ListPrice");

newItem.setProductId(new Number(productId));
newItem.setQuantity(new Number(1));
newItem.setUnitPrice(unitPrice);
try {
getDBTransaction().validate();
} catch (TxnValException e) {
System.out.println(e.getMessage());
for (Throwable t : e.getExceptions()) {
System.out.println(t.getMessage());
}
} catch (JboException e) {
System.out.println(e.getMessage());
}
}
}

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.)

Oracle University and Egabi Solutions use only


SequenceImpl seq = new SequenceImpl("ORDER_ITEMS_SEQ",
getDBTransaction());
populateAttributeAsChanged(LINEITEMID, seq.getSequenceNumber());
a. Double-click the OrderItemEOImpl.java file in the Application Navigator to open
the source fileit is located under the OrderItemEO node.
b. From the context menu, select Source > Override Methods.
c. In the Override Methods dialog box, select the check box next to the method
initDefaults() : void and click OK (whereas in the Override Methods dialog
box, you can just start entering the method name to navigate to it, or use the scroll
bar).

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


outside of the doc window to close it.
g. Right-click the editor and select Make and make sure that no compilation errors are
reported in the Compiler Log pane.
h. Save your work.
2. Test the assignment of the line item ID.
a. Run the FODShoppingCartAM application module.
b. Double-click OrderItemsOrdersFkLink1. This opens the master-detail window for
Orders and OrderItems.

c. Click Insert a new row in the bottom pane of the window (the OrderItems
section).
d. Note that the row is created with a LineItemId value defaulted from the database
sequence ORDER_SEQ.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Designate the column as a history column with the appropriate value:

Attribute Name History Column value


CreatedBy created by
LastUpdatedBy modified by

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, designate the same columns as history columns in OrderEO and OrderItemEO.
3. As you did previously for OrderEO and OrderItemEO, generate the entity object class for
SupplierEO.
4. In the entity object class for SupplierEO, override the
getHistoryContextForAttribute() method with the following code, which you can
copy from the getHistoryContextForAttribute.txt file in the \files subdirectory
of your \labs directory:
protected Object getHistoryContextForAttribute(AttributeDefImpl
attributeDefImpl) {
Object value =
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.)

Oracle University and Egabi Solutions use only


d. Substitute the code shown above for the generated code. You can copy the code from
the getHistoryContextForAttribute.txt file in the \files subdirectory of
your \labs directory.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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:

Oracle University and Egabi Solutions use only


1) Enter a name of StorefrontTest.
2) Make sure that only the Main Method check box is selected, and then click OK.

2. Use the bc4jclient shortcut to generate the test client code.


a. StorefrontTest.java opens in the editor. If it does not open, double-click it in the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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);
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()){

Oracle University and Egabi Solutions use only


Row paymentOptionRow = vo.next();
System.out.println(" CustomerID: " +
paymentOptionRow.getAttribute("CustomerId") +
" Payment Type Code: " +
paymentOptionRow.getAttribute("PaymentTypeCode"));
}
Your code should look like the following:

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

Practices for Lesson 7


Chapter 7 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 7


Chapter 7 - Page 13
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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 BaseApplicationModuleImpl.
2) Ensure that the package name is set to oracle.fod.storefront.module.
3) Next to the Extends field, click Browse.
a) In the Class Browser dialog box, click the Search tab and enter AMI
(uppercase) in the Match Class Name field, which displays a list of matching
classes.
b) Select the ApplicationModuleImpl(oracle.jbo.server) class and click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


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).

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

}
return mCurrentUser;

Oracle University and Egabi Solutions use only


4. Compile and save the code.
a. Right-click the editor and select Make.
b. Ensure that the log window displays no compilation errors. It should display the
message: Successful compilation: 0 errors, 0 warnings.
c. Save your work. The default preference in the IDE is to automatically save before
compiling.

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

Practices for Lesson 7


Chapter 7 - Page 16
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


2) Because you must use the method in the BaseApplicationModuleAMImpl class
that you created earlier, this application module class must extend that one, so
click Classes Extend.
3) In the Override Base Classes dialog box:
a) Click Browse next to the Object field.
b) In the Find Superclass dialog box, click the Search tab and enter BA in the
Match Class or Package Name field. This should populate Matching Classes
and Packages.
c) Select the BaseApplicationModuleImpl class and click OK.
d) Click OK again to close the Override Base Classes dialog box.
e. Click OK to generate the application module class.
f. Save your work.

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

Practices for Lesson 7


Chapter 7 - Page 17
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


b. You can see that the view objects and some operations are exposed to the client. Now
you add some service methods and expose them to the client as well.
2. Add a method to the shopping cart application module to initialize the shopping cart to that
of the current user of the application (remember that you hard coded the username in
BaseApplicationModuleImpl.java). The code is shown here: (You can copy the code
from the ShoppingCartInit.txt file in the \files subdirectory of your \labs
directory.)
public void init() {
DBTransactionImpl trx = (DBTransactionImpl)getDBTransaction();
ApplicationModuleImpl am =
(ApplicationModuleImpl)trx.getRootApplicationModule();
String user = am.getUserPrincipalName().toUpperCase();
System.out.println("The session user is: " + user);
ViewObjectImpl vo;
vo = getShoppingCart1();
String bindUser =
(String)vo.getNamedWhereClauseParam("CurrentUser");
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

cart.setAttribute("OrderDate",
((DBTransactionImpl)getDBTransaction()).getCurrentDbTime());
cart.setAttribute("OrderStatusCode", "CART");
vo.insertRow(cart);
}
}
}
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 University and Egabi Solutions use only


oracle.jbo.Row
oracle.jbo.server.DBTransactionImpl
oracle.jbo.server.ApplicationModuleImpl
3. Now add a method that adds an item to the users shopping cart. This method should call
an entity object method that you added earlier to OrderEOImpl.java. Use the following
code (you can copy from addItemToCart.txt):
public void addItemToCart(Number productId) {
init();
ViewObject shoppingCartVO = getShoppingCart1();
assert shoppingCartVO != null;

ViewRowImpl shoppingCartRow =
(ViewRowImpl)shoppingCartVO.first();
assert shoppingCartRow != null;

OrderEOImpl orderEO =
(OrderEOImpl)shoppingCartRow.getEntity(0);
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 7


Chapter 7 - Page 20
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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:

Oracle University and Egabi Solutions use only


1) The WHERE clause already reads:
OrderEO.CUSTOMER_ID = PersonEO.PERSON_ID
Append to the WHERE clause:
AND OrderEO.ORDER_STATUS_CODE = 'CART'
AND PersonEO.PRINCIPAL_NAME = :CurrentUser

2) Select Query > Bind Variables in the tree at the left.


3) In the Bind Variables panel, click New.
4) Enter a variable name of CurrentUser and click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. When the Business Components Browser appears, right-click the


FODShoppingCartAM node and select Show, or simply double-click the node.

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


d. Click Execute. The Result should be success.

Oracle University and Egabi Solutions use only


e. Double-click ShoppingCart1.
f. In the Bind Variables dialog box, click Cancel, because the init() method already
assigned the value to the bind variable.

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

Practices for Lesson 7


Chapter 7 - Page 22
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

g. One record should be returned by the query: the status CART order for DRAPHEAL.

Oracle University and Egabi Solutions use only


h. Close the Browser window.

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

Practices for Lesson 7


Chapter 7 - Page 23
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 7


Chapter 7 - Page 24
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 8


Chapter 8 - Page 1
Chapter 8

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


Practices for Lesson 8

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 8


Chapter 8 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 8


Chapter 8 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


Editor. Invoke the Add Validation Rule dialog box in one of the following ways:
1) With the OrderStatusCode attribute selected, click Edit. Then in the Attribute
Editor, select Validation in the tree at the left, and then click New.

2) Alternatively, after selecting the OrderStatusCode attribute in the Entity Object


Editor, in the Validation Rules accordion of the editor, click Add Validation Rule.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
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.

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. If you choose to define a text resource, simply click this option . In the Select Text

Oracle University and Egabi Solutions use only


Resource dialog box:
1) In the Display Value field, enter: You have entered an invalid value
2) In the Key field, enter: INVALID_VALUE
3) In the Description field, enter: Error message for invalid value
4) Click Save and Select.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.)

Oracle University and Egabi Solutions use only


c. In the Add Validation Rule dialog box:
1) Select UniqueKey from the Rule Type drop-down list.
2) Select OrdersPk(ORDER_ID) in the Keys list.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


4) Click OK to save your validation definition. You should see the new validation rule
in the Validation Rules section of the OrderEO editor.

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 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
file in the \files subdirectory of your \labs directory.)
public boolean validateShippedDateAfterOrderDate(Date
ordershippeddate) {
return ordershippeddate == null ||
ordershippeddate.dateValue().compareTo

Oracle University and Egabi Solutions use only


(getOrderDate().dateValue()) >= 0;
}
a. In the editor for the OrderEO entity, select the Attributes node, and then select the
OrderShippedDate attribute.
b. Invoke the Add Validation Rule dialog box as you did previously for the
OrderStatusCode attribute.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3) For Method Name, enter the value validateShippedDateAfterOrderDate

Oracle University and Egabi Solutions use only


d. On the Failure Handling tab:
1) Check whether the Validation Failure Severity option button is set to Informational
Warning.
2) As before, add, save, and use the message Order shipped date must not
be prior to order date, using a Key of SHIP_DATE_TOO_SOON and a
Description of Warning message for validation of shipping date.
Click Save and Select. Alternatively, you can just enter the message in the
Message Text field.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


i. Right-click and select Make.
j. 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 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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 customers email address.
1. Create a domain named PhoneNumber. It should be a string 12 characters in length with
the format xxx.xxx.xxxx.
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.

Oracle University and Egabi Solutions use only


4) Click Next.
c. On the Settings page of the wizard:
1) Select String from the Type drop-down list.
2) Click Next, and then click Finish.
d. In the Application Navigator, double-click PhoneNumber.java to open it in the editor. It
is located under the oracle.fod.storefront > domain > PhoneNumber node.

e. In the Structure window, double-click the validate():void node to navigate to that


method in the code.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Press Alt + Enter when prompted to accept the import of


oracle.jbo.domain.DataCreationException.
g. Right-click and select Make.
h. Save your work.

Oracle University and Egabi Solutions use only


2. Apply the domain to the PhoneNumber attribute of SupplierEO.
a. Open SupplierEO in the editor.
b. Click the Attributes tab.
c. Select the PhoneNumber attribute and click Edit (or simply double-click the attribute).
d. In the Edit Attribute dialog box:
1) Select Entity Attribute in the list at the left.
2) From the Type drop-down list, select
oracle.fod.storefront.domain.common.PhoneNumber.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


e. Change the OrderStatusCode to XXXX and tab out of the field. You should receive the
error message that you defined.
Note: If you defined the validation error message by entering hard-coded text, the error
message text looks the same, but the JBO error is a rather cryptic generated key
instead of INVALID_VALUE.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

c. Tab out of the field. You should receive the error message that you defined.

Oracle University and Egabi Solutions use only


d. Click OK to acknowledge the error.
e. Change the OrderId back to its original value so that you can navigate out of the field.
3. While still in FODShoppingCartAM, test the Method validator that you defined for the
OrderEO entity object.
a. Enter a value in Order Shipped Date that is later than the value in Order Date. You
should be able to tab out of the field with no error.

b. Enter the same value in Order Shipped Date that is in Order Date. You should be able
to tab out of the field with no error.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


should not be able to tab out of the field. Doing so should result in receiving the error
message that you defined.

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

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

Practices for Lesson 8


Chapter 8 - Page 16
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 9


Chapter 9 - Page 1
Chapter 9

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


Practices for Lesson 9

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 9


Chapter 9 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 9


Chapter 9 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


b. Navigate to the StorefrontDebug folder and open the StorefrontDebug application.
This application is identical to the one you have been working on, except that an error
has been introduced.
c. If prompted to migrate the application, perform the migration steps.
d. Modify the connection to point to your schema and edit the database information as
described in step 4 of Practice 2-4.
e. In the oracle.fod.storefront.module package, run FODShoppingCartAM.
f. Initialize the shopping cart:
1) In the Business Components Browser, double-click FODShoppingCartAM.
2) Select init from the Method drop-down list.
3) Click Execute to execute the init method.
g. Display the shopping cart:
1) Double-click ShoppingCart1.
2) In the Bind Variables dialog box, click Cancel so that the value that was set by
the init() method is used.
3) The cart does not display a users order, as expected, but instead displays a blank
(except for default values) new record.
h. Close the Business Components Browser.

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

Practices for Lesson 9


Chapter 9 - Page 4
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
a. In the Application Navigator, select FODShoppingCartAMImpl.java.
b. In the Structure window, right-click init():void and select Go to Source.

Oracle University and Egabi Solutions use only


c. To set a breakpoint, click in the left margin of the code editor next to the first line of
executable code in the init() method.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. In the Structure window, click the Show Fields button, and then right-click
mCurrentUser:String and select Create Watchpoint.

Oracle University and Egabi Solutions use only


3. View all the breakpoints that are set on the application.
a. From the JDeveloper main menu, select View > Breakpoints (or use the shortcut key
combination Ctrl + Shift +R).

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


b. Before the Business Components Browser appears, the debugger is invoked in the
JDeveloper IDE. Examine the information in the IDE.
1) BaseApplicationModuleImpl.java is shown in the editor with a watchpoint icon
and a pointer displayed to the left of the line setting mCurrentUser to null. This
is because the application has hit the watchpoint breakpoint that you set on this
variable.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
track of various values all in one place.

Oracle University and Egabi Solutions use only


3) Click Resume on the toolbar to continue the execution until the next time a
breakpoint is encountered. No breakpoint is encountered, so the Business
Components Browser appears.
4) Now set up the shopping cart as you have done before by executing the init()
methoddouble-click FODShoppingCartAM in the browser, select the init()
method from the Method drop-down list, and then click Execute. The control
passes to the debugger again, so click back within the JDeveloper window to
continue the actions.
5) FODShoppingCartImpl.java is shown in the editor with a source breakpoint icon
and a pointer displayed to the left of the line in the init() method where you set
the breakpoint.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

9) On the Smart Data tab, collapse all nodes, and then right-click user and select
Watch.

Oracle University and Egabi Solutions use only


The Watches tab now shows both the this.mCurrentUser and user variables
so that you can easily track their values.
10) Click Step Into to step into the getUserPrincipalName() method in
BaseApplicationModuleImpl.java. Note that when you do so, on the
Watches tab the user variable has question marks for value and type because it
is out of scope.
11) Click Step Into again twice. The pointer should now be on the line that assigns
a value to mCurrentUser, but that line of code has not yet been executed. You
can see that the value of the variable userPrincipal is about to be assigned to
mCurrentUser.
12) Click the Smart Data tab and notice that the value of userPrincipal is
"DRAPHAEL"this username is misspelled.
13) In the Smart Data panel, right-click the userPrincipal variable and select
Modify Value.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

15) Click Step Into (you


may have to click it twice). On the

Oracle University and Egabi Solutions use only


Watches tab, you should see that
mCurrentUser now has the value
DRAPHEAL, the correct spelling.
16) Click Step Out to execute the remaining lines of code in this method and return
to the FODShoppingCartAMImpl class.
17) Click the Watches tab, and then click Step Into and then Step Over . You
should see the value DRAPHEAL being assigned to user.
18) Click Step Over four times until the pointer is at the line of code that sets the
named WHERE clause parameter. This should set the bind variable of the view
objects query to return only the cart order belonging to the user DRAPHEAL.
19) Click the Smart Data tab and expand vo.mViewRowSet, and then place
mWhereParams on your watch list.
20) Click Step Over twice, so that the VO query executes, and then in the Watch
panel, expand mWhereParams and [0]. You should see that the Current User
parameter has been set to DRAPHEAL.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 10


Chapter 10 - Page 1
Chapter 10

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


Practices for Lesson 10

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 10


Chapter 10 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 10: Understanding UI Technologies


There is no practice for this lesson.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 10


Chapter 10 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 10


Chapter 10 - Page 4
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 11


Chapter 11 - Page 1
Chapter 11

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


Practices for Lesson 11

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 11


Chapter 11 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 11


Chapter 11 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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:

Oracle University and Egabi Solutions use only


1) Enter a file name of Products.
2) To the default Directory path, add \oracle\storefront\ui\pages.
3) Ensure that Create as XML Document (*.jspx) is selected, and then click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. Drag BrowseSubCategory1 to the page, selecting Master-Details > ADF Master


Table, Detail Table from the Create menu.

Oracle University and Egabi Solutions use only


3. By default, all attributes of the view objects were added to the tables. You want to display
only the category name and description. Delete the ones that you do not want to display,
and set the master table to enable row selection.
a. To edit the master table, select the top table (BrowseCategory) in either the visual
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.)

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


d. Select the second table (BrowseSubCategory1) in either the visual editor or the
Structure window and click Edit in the Property Inspector.
e. Set the column list to match the following (remove the extra columns and reorder as
needed):
CategoryName
CategoryDescription
f. Deselect the Row Selection check box and click OK. The page should now look
similar to the following screenshot, in which some of the extra white space has been
cut out:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:

Oracle University and Egabi Solutions use only


Note that the table does not fill the page. In the practice for the lesson titled Achieving
the Required Layout, you modify the layout so that the table fills the page.
d. Leave the browser window open to refer to in the next task.

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

Practices for Lesson 11


Chapter 11 - Page 7
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practice 11-2: Examining the Pages 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.

Oracle University and Egabi Solutions use only


For example, select the first column in the upper table in the JDeveloper editor, and then
look at the Property Inspector. What is the Header Text property set to?
__________________________________________________________________
__________________________________________________________________
Answer: #{bindings.BrowseCategory1.hints.CategoryName.label}
2. Select the CategoryName output text under the column header. What is its value?
__________________________________________________________________
__________________________________________________________________
Answer: #{row.CategoryName}
3. The reference to row is to a variable that is defined on the table.
Select the table in the Structure window, and then click the Source tab in the editor. How
is the row variable defined?
__________________________________________________________________
__________________________________________________________________
Answer:
var="row" value="#{bindings.BrowseCategory1.collectionModel}"
4. At run time, what appears in the browser for the first columns 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Answer: Category Name comes from the entity object attributes control hints for
Label.
6. At run time, what appears in the browser for the first columns values? Where do these
values come from?
__________________________________________________________________
__________________________________________________________________
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.)
__________________________________________________________________

Oracle University and Egabi Solutions use only


Answer: ProductsPageDef.xml
8. In the Model section of the page definition file, trace the source of the BrowseCategory1
binding. Where does the data come from?
__________________________________________________________________
__________________________________________________________________
Answer: The data comes from the BrowseCategory1 view object instance in the
FODProductAMDataControl. The data is held in the entity object on which the
BrowseCategory view object is based, and the values ultimately come from the
database.
9. At the top of the page, click the link to the Data Binding Registry. What is the name of this
file?
__________________________________________________________________
__________________________________________________________________
Answer: DataBindings.cpx
10. When does this data binding registry file get created? Hint: The answer is right at the top of
the Overview page for the data binding registry file.
__________________________________________________________________
__________________________________________________________________
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

__________________________________________________________________
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 11


Chapter 11 - Page 10
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


d. From the Create menu, select Table > ADF Read-only Table.
e. Do not enable Row Selection.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
b. Close the browser when you have finished and undeploy the application as described
in step 6(i) of Practice 2-4.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 11


Chapter 11 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


a. Reopen JDeveloper, and then open the ProductCatalog.jspx page in the editor.
b. Run ProductCatalog.jspx.
c. The browser displays error messages, but does not display any data.

d. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.
3. The Access Denied error that you received is indicative of a problem with data bindings.
Fix the problem without re-creating the tables on the page.
a. Click the Bindings tab in the editor of the ProductCatalog page to see that there are
no data bindings for the page.
b. 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


d. Save your work.
4. Test the ProductCatalog page again.
a. Close and reopen ProductCatalog.jspx in the editor.
b. Click the Bindings tab. You should see data bindings, and the Page Definition File
should be listed as oracle/storefront/ui/pages/ProductsPageDef.xml.
c. Run the page. The data should now be displayed correctly.
d. Close the browser when finished, and undeploy the application as described in step
6(i) of Practice 2-4.
5. If you have time, as an optional exercise, rename the page definition file to match the
new name of the page.
a. Close JDeveloper, saving any unsaved work and terminating any running processes if
prompted.
b. In Windows Explorer, navigate to your application directory.
c. In the StorefrontUI\adfmsrc\oracle\storefront\ui\pages directory,
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. In the Structure window, right-click the ProductsPageDef node and select Refactor >
Rename.

g. In the Rename dialog box, change ProductsPageDef to


ProductCatalogPageDef.

Oracle University and Egabi Solutions use only


This changes the ID of the page definition. Alternatively, you could change the ID in the
Property Inspector.
h. In the Application Navigator, navigate to StorefrontUI > Application Sources >
oracle.storefront.ui and open DataBindings.cpx.
i. Map the renamed page definition file to the path of the existing page: In the Page
Definition Usages section of DataBindings.cpx, select the path, and then in the
Property Inspector, change the value of the path from ProductsPageDef to
ProductCatalogPageDef.

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

Practices for Lesson 11


Chapter 11 - Page 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


3) In the <pageDefinitionUsages><page> section, change the id to be the same as
the usageId in the previous section. The red squiggly line should disappear.

4) If desired, retest the page.

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

Practices for Lesson 11


Chapter 11 - Page 16
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 12


Chapter 12 - Page 1
Chapter 12

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


Practices for Lesson 12

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 12


Chapter 12 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


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.

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

Practices for Lesson 12


Chapter 12 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
rest of the application, add the ProductCatalog page to the applications 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.

Oracle University and Egabi Solutions use only


b. Drag ProductCatalog.jspx from the Application Navigator to the task flow that is open
in the editor.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


2. Create two additional view activities in the unbounded task flow named ProductSearch
and ProductDetails.
a. In the Component Palette, ensure that ADF Task Flow is selected in the drop-down list
at the top. Expand the Components category and drag a View activity to the editor.

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

Practices for Lesson 12


Chapter 12 - Page 5
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


c. Similarly, add another view activity named ProductDetails.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


c. Enter detail as the name of the case. You can enter directly on the diagram, or it
may be easier to use the Property Inspector and enter the name as the from-
outcome of the control flow case.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

5. Add a Control Flow Case from ProductCatalog to ProductSearch and name it search.

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

Oracle University and Egabi Solutions use only


7. Add a control flow case named detail from ProductCatalog to ProductDetails.
8. Add a control flow case named shop from ProductDetails to ProductCatalog.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 12


11. Save your work.

Chapter 12 - Page 9
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
b. In the Categories list, expand Web Tier and select JSF.
c. In the Items list, select ADF Task Flow and click OK.

Oracle University and Egabi Solutions use only


d. In the Create Task Flow dialog box:
1) Set File Name to ShoppingCartFlow.
2) To the directory path, add \oracle\storefront\ui\flow. This is the path you
should use for all task flows.
3) Ensure that Create as Bounded Task Flow is selected.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Note that the newly created task flow appears in the Application Navigator in two
places, both under WEB-INF and under Page Flows.

Oracle University and Egabi Solutions use only


f. The Shopping Cart flow opens in the editor. Add a view activity and name it
ShoppingCart.

Note that the view activity is surrounded with a green halo. This indicates that it is the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


i. Add a Control Flow Case from ShoppingCart to the Shop task flow return activity
and name it too as shop.

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

Practices for Lesson 12


Chapter 12 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

j. Similarly, add another task flow return activity called Checkout, with the outcome
name checkout.

Oracle University and Egabi Solutions use only


k. Add a control flow case also named checkout from ShoppingCart to Checkout.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) A task flow return activity named Save whose outcome is named done

Oracle University and Egabi Solutions use only


3) A task flow return activity named Cancel whose outcome is also named done

4) A wildcard control flow rule

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

Practices for Lesson 12


Chapter 12 - Page 14
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

5) Control flow cases between the activities:


From To Name
SupplierUpdate Save save
Wildcard Cancel cancel

Oracle University and Egabi Solutions use only


b. In the same way, create the ShowSuppliersFlow in the
\oracle\storefront\ui\flow subdirectory, with one view activity named
BrowseSuppliers.

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

Practices for Lesson 12


Chapter 12 - Page 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Right-click one of the selected objects and select Extract Task Flow.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


f. In the editor, arrange the ShoppingFlow activities in a visually pleasing manner, such
as shown below:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


The ProductCatalog activity is now surrounded with a green halo indicating that it is the
default activity, or entry point, for the task flow.
h. When you extract a bounded task flow, a task flow call activity is created on the task
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.
1) Open or switch to adfc-config.xml.
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.

i. Save your work.

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

Practices for Lesson 12


Chapter 12 - Page 18
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 13


Chapter 13 - Page 1
Chapter 13

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


Practices for Lesson 13

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 13


Chapter 13 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


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.

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

Practices for Lesson 13


Chapter 13 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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 users cart
(those order items for the user whose status is CART).
1. Create the ShoppingCart page.
a. Open ShoppingCartFlow in the editor.
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.

Oracle University and Egabi Solutions use only


2. Create a read-only table on the page to display the users 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


b. Ensure that Row Selection is enabled.
c. Delete all but the following attributes and arrange them in order:
ProductName
ListPrice
Quantity
LineTotal

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


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
Controller in this case because you are not using any control flows to test this single
page. In most cases, however, you should run pages from a task flow rather than
running them directly.
You also receive several compilation warnings: XML-24521: (Error) Element not
completed: 'view', because you have created several activities in task flows that have
not been completed, such as view activities without corresponding pages. You can
safely ignore these warnings.
c. The page runs, but does not show any data. ShoppingCart is tied to a specific user;
however, you have not yet told it what user.

d. Close the browser when you have finished and undeploy the application as described
in step 6(i) of Practice 2-4.
4. Add to the page an invocation of the application modules init() method that initializes
the application to show shopping cart data for a specific user. The method interrogates the
system user (a hard-coded name is used until security is implemented in a later practice)
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


3) In the Create Action Binding dialog box, select
FODShoppingCartAMDataControl, choose init() from the Operation drop-
down list, and then click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

1) In the Executables section, click Add .

2) In the Insert Item dialog box, select invokeAction, and then click OK.
3) In the Insert invokeAction dialog box:

Oracle University and Egabi Solutions use only


Enter an ID of invokeInit, select init from the Binds drop-down list, and click
OK.

4) In the Property Inspector, set Refresh to ifNeeded.

5) In the Executables panel, drag the invokeInit executable to the top position, so
that the init() method is invoked before the iterator.

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

Practices for Lesson 13


Chapter 13 - Page 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:

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

Oracle University and Egabi Solutions use only

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

Practices for Lesson 13


Chapter 13 - Page 9
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


b. In the Edit Table Columns dialog box:
1) Enable Row Selection.
2) Include only the following four attributes in this order:
ProductName
CategoryName
ListPrice
Description

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

Practices for Lesson 13


Chapter 13 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


3. Test the functionality of the ProductSearch page.
a. Right-click the editor for the ProductSearch page and select Run. (Do not run the
page from the task flow because the default activity of the task flow does not yet have
the ability to navigate to the ProductSearch page.)
NOTE: Although this page is represented as a view activity on the bounded task flow
that is not the default activity, you can still run the page separately when you are not
running it from the task flow. It is the task flow that has a single entry point, not
individual pages.
b. The page runs and looks similar to the following:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

1) Enter a percentage sign (%) in the ProductName field and click Search. All of the
products appear.

Oracle University and Egabi Solutions use only


2) Resize columns in the table by dragging the lines between the column headers.
3) Reorder columns in the table by dragging column headers.

4) Click Advanced to enable more search options.


5) 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

6) Enter Pla in the ProductName search field and click Search. Note that the table
displays products that contain Pla.

Oracle University and Egabi Solutions use only


7) Select Does not contain from the operators drop-down list and click Search.
Now the table displays only those products that do not contain the string Pla.

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

Practices for Lesson 13


Chapter 13 - Page 14
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

8) Select Price from the Add Fields drop-down list.

Oracle University and Egabi Solutions use only


9) For the Price criterion, select Greater than from the operators drop-down list,
enter a value of $1000 (ListPrice is formatted as currency), and then click Search.
Now the table displays only those products that do not contain the string Pla and
whose list price is more than $1000.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


a. Drag the Data Control FODProductAMDataControl > BrowseProduct to the visual
editor and select Form > ADF Read-only form from the context menu.

b. In the Edit Form Fields dialog box:


1) Include only the following fields in order:
ProductName
CategoryName
ListPrice
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3. Run the page to test it. Run it directly rather than from the task flow because you have not
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

Oracle University and Egabi Solutions use only


step 6(i) of Practice 2-4.

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

Practices for Lesson 13


Chapter 13 - Page 17
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


a. From the Data Controls panel, drag to the page FODSupplierAMDataControl >
Supplier1 as a Table > ADF Read-only Table.

b. Use only the first five attributes.


c. Enable Row Selection and Sorting.

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

Practices for Lesson 13


Chapter 13 - Page 18
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:

Oracle University and Egabi Solutions use only


b. Test that you are able to sort columns and select rows.

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 13


Chapter 13 - Page 19
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Create a .jspx page in the directory where you are creating pages
(\oracle\storefront\ui\pages).
2. Add a tree to the ProductCategory page to display categories and subcategories.
a. From the Data Controls panel, drag to the page FODCategoryAMDataControl >
RootCategory1 as a Tree > ADF Tree.

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

Practices for Lesson 13


Chapter 13 - Page 20
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. In the Edit Tree Binding dialog box, select SubCategory from the Add Rule drop-
down list.

Oracle University and Egabi Solutions use only


c. Select the oracle.fod.storefront.uiview.RootCategoryVO(<SubCategory>) tree level
rule.
d. Shuttle CategoryName from the Available Attributes list to the Display Attributes list,
and remove CategoryDescription from the Display Attributes list.

e. Now, select the oracle.fod.storefront.uiview.BrowseSubCategoryVO tree-level rule.


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
page.
g. The page should look similar to the following:

Oracle University and Egabi Solutions use only


3. Convert the output text to a command link.
a. On the ProductCategory page, select af:outputText in either the Structure window
or the visual editor. (You must keep expanding the af:tree node all the way to find
af:outputText.)
b. Right-click af:outputText and select Convert To.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. In the Properties Inspector, set the Text to #{node}. (You can use Expression
Builder and select the expression from JSP Objects.)

4. Test the ProductCategory page.


a. Run the ProductCategory page from either the page editor or from the task flow. The

Oracle University and Egabi Solutions use only


page should look similar to the following when you expand the category nodes:

b. Note that you can expand the nodes, but nothing happens when you click the links
other than that the tree is refreshed. You change this behavior in a later practice.
c. When 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 23
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


node, and then select LOV_SupplierStatus and click Edit.

g. In the List of Values editor:


1) Click the Configuration tab, where you can see that SupplierStatus will be
selected from the available LookupCode rows in the LookupCodeVVO1 view
accessor, and that the LookupCode value will be returned to the SupplierStatus
attribute when the user selects a value from the list.
2) Click the UI Hints tab, where you can see that the attribute appears as a Choice
List containing the LookupCode and Description.
3) Click Cancel.
h. Open SupplierEO under the StorefrontModel > Application Sources >
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

k. You can see that the view accessor limits the view to those rows where the lookup type
is SUPPLIER_STATUS_CODE.

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

Oracle University and Egabi Solutions use only


been creating pages (\oracle\storefront\ui\pages). The form needs to show only
one record.
a. Open the ManageSupplierFlow task flow from the Application Navigator if it is not
already open.
b. Create the SupplierUpdate page, placing it in a supplier subdirectory
\oracle\storefront\ui\pages\supplier.

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

Practices for Lesson 13


Chapter 13 - Page 25
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

c. Drag the data control FODSupplierAMDataControl > Supplier1 to the page and
create an ADF Form.

Oracle University and Egabi Solutions use only


d. Select only the following fields:
SupplierName
SupplierStatus
PhoneNumber
Email
Do not include Navigation Controls or a Submit Button.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Test the page by running it directly. The page should look similar to the following with
the list of values dropped down:

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

Oracle University and Egabi Solutions use only

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

Practices for Lesson 13


Chapter 13 - Page 27
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Click OK.

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

Practices for Lesson 13


Chapter 13 - Page 28
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 14


Chapter 14 - Page 1
Chapter 14

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


Practices for Lesson 14

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 14


Chapter 14 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


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
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.

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

Practices for Lesson 14


Chapter 14 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


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.
(You may find it easier to drag it to the Structure windowexpand af:form and drag
the button just above af:panelFormLayout.)

The page should look similar to the following:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


f. The label of the button changes to Cancel.
Note: The label of the button may appear at design time as the EL expression
#{storefrontuiBundle.CANCEL}.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

This ensures that the cancel control flow is executed when the user clicks the Cancel
button.
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.

Oracle University and Egabi Solutions use only


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.)
The ManageSupplierFlow task flow has a control flow rule from SupplierUpdate to the Save
task flow return activity whose from-outcome is save. Follow a similar series of steps to
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
select the save action. Do not change the default value of the Immediate property for this
button.

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

Practices for Lesson 14


Chapter 14 - Page 6
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


4. Optional step: (If you choose not to create these buttons, you must begin the
practices for the next lesson by opening the starter application.)
Following a similar series of steps, add the following buttons for navigation, optionally using
a text resource for the label of each:
Task Flow Page Button Label Button
Action
ShoppingFlow ProductDetails Search (use the search
existing text resource)
ShoppingFlow ProductDetails Shop (create a text shop
resource entry)
ShoppingCartFlow ShoppingCart Shop (use the existing shop
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. Double-click StorefrontUIBundle.properties to open it in the editor.

c. The file should look similar to the following (not all of these entries are present if you
skipped any optional steps):

Oracle University and Egabi Solutions use only


Note: Although subsequent practices specify the use of a resource bundle to
store translatable strings, in the interest of time, you may choose to just enter
the strings as hard-coded text.
d. Close all editor windows.

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

Practices for Lesson 14


Chapter 14 - Page 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


2) Click Edit on the Property Inspector.

3) In the Edit Table Columns dialog box, deselect the Row Selection check box, and
then click OK.
c. Change the ProductName to be a link that calls the ADF method that sets the row and
then navigates to the detail page:
1) In the Structure window, expand the first af:column under af:table.
2) Right-click af:outputText for ProductName in the Structure window and select
Surround With.

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

Practices for Lesson 14


Chapter 14 - Page 9
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3) In the Surround With dialog box, select ADF Faces > Link and click OK.

Oracle University and Egabi Solutions use only


4) In the Property Inspector, remove the value in the Text property of the
af:commandLink and set Action to detail.

d. If you run the page from the task flow at this point (see step f below for how to do that if
you want to try), the link navigates to the detail page but always displays details for the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) Drag the setCurrentRowWithKey operation to the af:commandLink in either


the Structure window or the editor, and select Bind Existing Link.

Oracle University and Egabi Solutions use only


3) Click OK to close the Edit Action Binding dialog box.
4) In the Confirm Component Rebinding dialog box, select the Keep Current Value
check boxes for the text and action properties. Click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) In the Structure window, select bindings > setCurrentRowWithKey > rowKey.

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

Oracle University and Egabi Solutions use only


changing field focus, the IDE accepts the value that you entered.)

f. Test the links in the ShoppingFlow task flow.


1) In the ShoppingFlow task flow, right-click the ProductCatalog view activity and
select Run.
2) On the ProductCatalog page, click Search.
3) On the Search page, enter % in the ProductName field and click Search.
Experiment with using the link on the product name.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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}.

Oracle University and Egabi Solutions use only


d. Right-click the af:outputText and select Convert To.
e. In the Convert Output Text dialog box, select ADF Faces > Link and click OK.

Click OK to confirm Convert.


f. Paste the copied value into the Text property of the commandLink.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


c. In the Edit Action Binding dialog box, click OK.
d. In the Confirm Component Rebinding dialog box, select the text check box to retain its
value and click OK.

e. Select af:commandLink and set the Action property to detail.


4. The setCurrentRowWithKeyValue method uses an argument (ND or Named Data) to
tell it which row is current. The argument for setting the current row of Product is ProductId.

When you created the Product table for this page, you excluded the ProductId because you
do not want to display it. Because it was excluded, it is not in the page bindings. Before you
can use ProductId as an argument to the setCurrentRowWithKeyValue method, you
have to add it to the bindings. After you add it, you can set the NDValue property of
setCurrentRowWithKeyValue.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


Note: This adds the attribute to the bindings, but it does not add it to the table on the
page. It simply makes the attribute available to the page.
d. The setCurrentRowWithKeyValue method uses an argument (ND or Named Data)
to tell it which row is current. The argument for setting the current row of Product is
ProductId.
In the Structure window, select bindings > setCurrentRowWithKeyValue > rowKey
and set the NDValue property to #{row.ProductId}. Be sure to tab out of the field or
click in another field so that the value is saved.

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

Practices for Lesson 14


Chapter 14 - Page 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

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 browsers Back button to return to

Oracle University and Egabi Solutions use only


the ProductCatalog page.)
Note: If the Products table at the bottom shows no data, you can test the links after
you coordinate the Products table with the Subcategories table in a later practice.
g. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.
5. On the ShowSuppliersFlow task flow, create a task flow call activity to invoke the
ManageSupplierFlow task flow, a control flow case named update from BrowseSuppliers
to ManageSupplierFlow, and a control flow case named done from ManageSupplierFlow to
BrowseSuppliers. You want users to be able to click the SupplierId to be able to update the
supplier. Convert the SupplierId on the BrowseSuppliers page to a link that implements this
navigation. You do not need to disable row selection for this table.
a. Open the ShowSuppliersFlow task flow.
b. From the Application Navigator, drag ManageSupplierFlow to the diagram to create a
task flow call activity.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


3) In the Surround With dialog box, select ADF Faces > Link and click OK.
4) In the Property Inspector of the af:commandLink:
a) Remove the value in the Text property
b) Set the Action to update
5) On the Behavior tab, set the PartialSubmit property to true.
g. Test the page by running BrowseSuppliers from the ShowSuppliersFlow task flow.
When you click a link, you should navigate to the supplier update page.

However, the page does not yet commit any updates you may make for the selected
supplier; you implement that in a later practice.
h. When you have finished, close the browser and undeploy the application as described
in step 6i of Practice 2-4.

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

Practices for Lesson 14


Chapter 14 - Page 17
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


3. Drag three Navigation Items to the af:breadCrumbs component.
4. Select the first af:commandNavigationItem and use a resource bundle to change its
Text property to Store, or optionally, just enter the text.
5. You will not be able to test the navigation until after you add the dynamic breadcrumbs
functionality in a later practice. For now, just leave the other two navigation items as they
are.

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

Practices for Lesson 14


Chapter 14 - Page 18
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


b. To the Directory path, append \oracle\storefront\ui\flow.
c. Ensure that Create as Bounded Task Flow is selected.
d. Ensure that Create with Page Fragments is not selected.
e. Select the Create Train check box.

f. Click OK.

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

Practices for Lesson 14


Chapter 14 - Page 19
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

5. Add two task flow returns:

Oracle University and Egabi Solutions use only


a. Name one task flow return SubmitOrder, and set the name of its outcome in the
Property Inspector to submit.

b. Name the other task flow return CancelOrder, and set the name of its outcome in the
Property Inspector to cancel.
c. Add a wildcard control flow rule.
d. Add two control flow cases:
1) One named submit from CheckoutConfirm to SubmitOrder
2) One named cancel from the wildcard to CancelOrder

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2) Include the following attributes in order, deleting all other attributes:


Address1
Address2
City
StateProvince
PostalCode

Oracle University and Egabi Solutions use only


CountryId
3) Do not include Navigation Controls or a Submit Button.
4) Click OK to create the form.
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
navigation. You fix these problems in the next steps.

When finished, close the browser and undeploy the application as described in step 6(i) of
Practice 2-4.
8. Establish the context for the shopping cart by calling the init() method defined in the
FODCheckoutAMDataControl application module. Add a reference to the init()
method and execute the method as part of the page load process. This init() method
retrieves the current username (now hard coded, but when security is implemented will be
set programmatically), sets the value in a named WHERE clause, and then reexecutes the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


2) Click OK.
e. Now that you have a reference to the init() method, you can add it to the
Executables list:
1) Click Add in the Executables section.
2) Select Generic Bindings > invokeAction and click OK.
3) In the Insert InvokeAction dialog box, set id to invokeInit, and set Binds to init,
and then click OK.

4) In the Property Inspector, set the Refresh property to ifNeeded.


Note: By setting the Refresh property to ifNeeded, the framework refreshes the
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 users 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

a. In the page editor for the CheckoutShipping page, drag a Train component from the
Component Palette just inside the top of the form.

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

Oracle University and Egabi Solutions use only


after the af:train.
b. In the Bind trainButtonBar dialog box, click OK to accept the default trainModel to
bind to.
Note: Ensure that the train button bar appears in the Structure window between the
train and the panel form layout. The Structure window should look like this (if not, drag
components to rearrange them):

11. Add labels for the train stops: Shipping, Billing, and Confirmation. JDeveloper
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


c. In the Property Inspector, change the Value of the Output Text item to reflect the title of
the pageCheckout Payment or Checkout Confirm. You do not need to place
that text in the resource bundle because you do not use it on the permanent page that
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.
d. Run the CheckoutShipping page from the task flow to see the results. The navigation
train and button bar appear, with labels for each train stop. You can use either the
Billing link or the Next button to navigate to the payment page.

However, because you have added the train component and train button bar to only the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 14


Chapter 14 - Page 25
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


d. Delete the other search control flow rule. The diagram should now look similar to the
following screenshot:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

g. Select the shop control flow rule and in the Property Palette, change its from-activity-

Oracle University and Egabi Solutions use only


id to the wildcard rule by selecting it from the drop-down list.
h. Rearrange the items on the diagram to look similar to the following screenshot:

2. Add three task flow call activities to the ShoppingFlow:


To call the checkout flow
To display the shopping cart
To add an item to the cart
a. From the Application Navigator, drag CheckoutFlow to the ShoppingFlow task flow
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


e. Drag a Control Flow Case from the wildcard to AddShoppingCart and name the
outcome add.

f. From the Application Navigator, again drag ShoppingCartFlow to the ShoppingFlow


task flow diagram in the editor to create a task flow call activity.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


3) Test the navigation with the Show Cart button by running the ProductCatalog
page from the ShoppingFlow task flow.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 14


Chapter 14 - Page 30
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 15


Chapter 15 - Page 1
Chapter 15

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


Practices for Lesson 15

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 15


Chapter 15 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


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.

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

Practices for Lesson 15


Chapter 15 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


ProductCatalog Subcategories table
ProductCatalog Products table
ProductSearch (optional) Search results table
ShoppingCart (optional) Items table
BrowseSuppliers (optional) Suppliers table
a. In the Application Navigator, select the ProductCatalog page.
b. In the Structure window or in the editor, select the af:table masterDetail1
component.
c. In the Property Inspector, set the Appearance > Width to 100%. Tab out or click in any
other field to apply the new value. You can see the effects of table stretching in the
editor, as the table boundaries expand to fill the horizontal space in the editor.
d. Select last from the Column Stretching drop-down list.
You can see the effects of column stretching in the editor, as the last column expands
to fill up the space.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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)

Oracle University and Egabi Solutions use only

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

Practices for Lesson 15


Chapter 15 - Page 5
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practice 15-2: Adjusting JDevelopers 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.
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.

Oracle University and Egabi Solutions use only


1) In the Structure window, select af:panelHeader BrowseCategory1.

2) In the Property Inspector, change the Text property to Categories. Ensure that
you use a resource bundle.
3) 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. In the Property Inspector, select scroll from the Layout drop-down list.

Oracle University and Egabi Solutions use only


c. Drag the Products table to the af:panelGroupLayout scroll component.

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, open ProductSearch page and set the default Panel Group Layout component
to scroll.

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

Practices for Lesson 15


Chapter 15 - Page 7
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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 Products,
optionally using a resource bundle.
f. Save your work.
2. On the ProductDetails page, place the Product form, which is contained by default in a
panel form layout, into a panel header titled Product Detail. Add a toolbar for the existing
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


h. Drag the existing Search and Shop buttons to the toolbar, in either the Structure
window or in the editor.

i. Save your work. When you have finished, the page should look similar to this

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


500 pixels.

e. Save your work. When you have finished, the page should look like this

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


b. Use the resource bundle to change the Text to Shopping Cart.
c. Add a Toolbar component and move the existing buttons to the toolbar facet of the
panel header.
d. Save your work.
6. 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 CheckoutShipping page, put the panelFormLayout containing the
Shipping form into a panel header titled Shipping Address.
a. Surround the Panel Form Layout with a Panel Header.
b. Use the resource bundle to change the Text to Shipping Address.
c. Do not move the train or the train button bar into the panel form layout.
d. Save your work. When you have finished, the Structure window should look like this:

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

Practices for Lesson 15


Chapter 15 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
options. The final layout should be something like this:

Oracle University and Egabi Solutions use only


a. Open the CheckoutFlow task flow.
b. Double-click the CheckoutPayment view activity to create the page. Ensure that you
create it in the \oracle\storefront\ui\pages directory.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


b. Create it as a Form > ADF Form.
c. Include the following attributes in order, deleting others:
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. Save your work. The page should now look like this:

Oracle University and Egabi Solutions use only


3. In a similar manner, add the payment options.
a. Drag the FODCheckoutAMDataControl > ShoppingCart1 > PaymentOption1 data
control to the second panel header on the page and add it as an ADF Form.
b. Include the following attributes in order, deleting others:
PaymentTypeCode
CardTypeCode
AccountNumber
ExpireDate
CheckDigits
RoutingIdentifier
InstitutionName
c. Do not include Navigation Controls or a Submit Button.
d. Click OK.
e. Save your work. Now the page should look like this:

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

Practices for Lesson 15


Chapter 15 - Page 14
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

f. Add some white space between the panels.


1) Drag a Spacer from the Component Palette to the Panel Group Layout facets >
separatorthis 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
this:

Oracle University and Egabi Solutions use only


a. In the CheckoutFlow task flow diagram, double-click the CheckoutConfirm view
activity to create the CheckoutConfirm page in the \oracle\storefront\ui\pages
directory.
b. From the Component Palette, drag a Panel Group Layout to the page and set its
Layout property to scroll.
c. Drag a Panel Header to the Panel Group Layout and set its Text property to Payment
Options, optionally using an existing text resource.
d. 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

The page should look like the following:

Oracle University and Egabi Solutions use only


5. Now that you have defined the layout, you can create databound components on the page.
Create a read-only table of shopping cart items on the Order Items panel header, and read-
only forms for shipping address, billing address, and payment options on their respective
panel headers.
a. Drag the FODCheckoutAMDataControl > ShoppingCart1 > PaymentOption1 to the
Payment Options panel header as Form > ADF Read-only Form.

1) Include the following attributes in order, deleting others:


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

1) Include the following attributes in order, deleting others:


Address1
Address2
City
StateProvince
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.

Oracle University and Egabi Solutions use only


1) Include the following attributes in the same order:
Address1
Address2
City
StateProvince
PostalCode
CountryId
2) Do not include Navigation Controls or a Submit Button.
d. 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


and the Structure window should look like this:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


e. Open the CheckoutPayment page.
f. In the Structure window, expand jsp:root > f:view > af:document > af:form.
g. Right-click af:form and select Paste.
h. Drag af:train and af:trainButtonBar above the af:panelGroupLayout.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


DD Direct Debit
IN Invoice
PP PayPal
1. The PaymentTypeCode is a choice list and its default binding gives you the position of the
selected value in the list, not the value. On the CheckoutPayment page, create an attribute
value named PaymentTypeCodeValue for the value of the payment type code.
a. Click the Bindings tab on the CheckoutPayment.jspx page.
b. In the Bindings section, click Add .
c. Select Generic Bindings > attributeValues.
d. Click OK.
e. In the Create Attribute Binding dialog box:
1) Select FODCheckoutAMDataControl.PaymentOption1 as the Data Source and
PaymentTypeCode as the Attribute.
2) Click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. Select af:selectOneChoice for PaymentTypeCode in either the visual editor or the


Structure window.
c. Set the Id property to PaymentType.

Oracle University and Egabi Solutions use only


d. Set the Behavior > AutoSubmit property to true.
3. The first attribute to set a condition on is CardTypeCode. If the payment type code is not
CC (for Credit Card), then do not display this field.
a. Select af:selectOneChoice for CardTypeCode attribute in either the visual editor
or the Structure window.
b. Set the Visible attribute (in the Advanced panel) to:
#{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
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Note: Be sure to select the PaymentTypeCodeValue attribute binding and not the
PaymentTypeCode binding.

Oracle University and Egabi Solutions use only


c. Now set the PartialTriggers property to PaymentType, which is the ID of the
triggering component.
1) On the Behavior panel, click the small down arrow next to the PartialTriggers
text box and select Edit.
2) In the Edit Property dialog box, select selectOneChoice PaymentType and
shuttle it to the Selected list. (This means that when the PaymentType component
forces an autosubmit, it refreshes this data control. When it does, the code in the
Visible property executes. If the code evaluates to true, the data control
appears.)

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

Practices for Lesson 15


Chapter 15 - Page 22
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
#{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 >

Oracle University and Egabi Solutions use only


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.
Note : Ensure that you select the PaymentTypeCodeValue attribute binding and not
the PaymentTypeCode binding.
c. Now set the PartialTriggers property to PaymentType, which is the ID of the
triggering component.
1) On the Behavior panel, click the small down arrow next to the PartialTriggers
text box and select Edit.
2) In the Edit Property dialog box, select selectOneChoice PaymentType and
shuttle it to the Selected list.
5. In the same way, set CheckDigits to be visible only if the value is CC.
a. Select af:inputText for CheckDigits attribute in either the visual editor or the
Structure window.
b. Repeat steps (4b)(4c) and code are similar.
6. Set RoutingIdentifier and InstitutionName to be visible only if the value is DD.
Hint: Remember to set the expression for the Visible property and select PaymentType for
the PartialTriggers property for these attributes.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


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 15


Chapter 15 - Page 24
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


Property Inspector. (Do not just change the Row Selection property in the property
inspector.)

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

c. In the Edit Property dialog box, shuttle SubCategory in the Selected pane.

Oracle University and Egabi Solutions use only


d. Click OK.
3. Test the page.
a. Run the page, either directly or from the task flow.
b. Select Category, then SubCategory and check that the correct products appear.
c. When you have finished, close your 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 15


Chapter 15 - Page 26
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 16


Chapter 16 - Page 1
Chapter 16

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


Practices for Lesson 16

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 16


Chapter 16 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


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
regions on the main FODShoppingDashboard page. To do so, you must first convert the
bounded task flows to use page fragments.
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-16.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.

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

Practices for Lesson 16


Chapter 16 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


You should also see that the .jspx files for the checkout pages have been converted to
.jsff files.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


a. Open adfc-config.xml. Make sure that the views appear in the diagram.
b. Right-click the ProductCategory view activity and select Extract Task Flow. Click
Yes in the Warning dialog box.
c. In the Extract Bounded Task Flow dialog box:
1) Enter ProductCategoryFlow as the File Name.
2) Append \oracle\storefront\ui\flow to the Directory path.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


g. Save your work.

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

Practices for Lesson 16


Chapter 16 - Page 6
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


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:
File Name: CheckoutPageTemplate.jspx

Directory: <ProjHome>\public_html\oracle\storefront\ui\
pages\templates
Page Template Name: CheckoutPageTemplate

Facet Definitions tab (Click the Add icon to add the facet.)
Name: content

d. Click the Attributes tab to specify the following:


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


b. Drag a Train to af:panelGroupLayout.
c. Set the Value property of af:train to
#{controllerContext.currentViewPort.taskFlowContext.trainModel}.
(You can use Expression Builder and select ADF Controller Objects >
controllerContext > currentViewPort > taskFlowContext > trainModel to insert into
the expression.)

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Add a Facet Reference named content to the template.


1) Drag Facet Ref to af:panelHeader.
2) Set FacetName to content.

f. Expand the af:panelHeader > Panel Header facets node in the Structure pane.
g. Add a Toolbar to af:panelHeader > Panel Header facets > toolbar.

Oracle University and Egabi Solutions use only


h. Add a Button to af:toolbar.
1) Set the Text to Cancel, optionally using the resource bundle.
2) Enter cancel for the Action property.

3) Set the Immediate property to true.


i. Add a Train Button Bar to af:toolbar inside the af:panelHeader toolbar facet
and set the Value property to
#{controllerContext.currentViewPort.taskFlowContext.trainModel}.
j. Add another Button to af:toolbar inside the af:panelHeader toolbar facet.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3) Using the Expression Builder, set the Disabled property to


#{controllerContext.currentViewPort.taskFlowContext.trainMode
l.next ne null}.

Oracle University and Egabi Solutions use only


Note: If you use the Expression Builder, it displays the code as if it were an error.
It has context for the trainModel, but does not understand .next in the
expression. You can ignore the error.
3. Save your work. The page template should look similar to the following

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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">

Oracle University and Egabi Solutions use only


<f:facet name="content"/>
<f:attribute name="title"/>
</af:pageTemplate>

The error will be solved in the following steps.


e. Click the Design tab.
f. Note that in the Structure window, there is now an af:pageTemplate, an
f:attribute, and a content facet. Set the Value property of f:attribute to
Shipping, optionally using the resource bundle.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. Repeat the steps above, changing the value of the title attribute to Billing. (The
content area of this page is in the panelGroupLayout.)

c. Open CheckoutConfirm.jsff.

Oracle University and Egabi Solutions use only


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.)
7. Save your work.

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

Practices for Lesson 16


Chapter 16 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
available.
In this practice, you create a page template to be used on the main page of any of the
companys applications. You then create the FODShoppingDashboard page and base it on this
template. The layout of the template should be as follows:

Oracle University and Egabi Solutions use only


1. In the templates subdirectory of your directory for pages, create a new page template
named MainPageTemplate. Define content areas named companyLogo, tab1Content,
tab2Content, and mainContent. Define required attributes called companyName,
tab1Title, and tab2Title.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


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.
The component should be one that automatically stretches its children. Stretch it to fit the
browser vertically and horizontally.
a. Drag a Panel Splitter to the page. Ensure that it appears above af:xmlContent in the
Structure window.
1) Set its Orientation to vertical.
2) Set its SplitterPosition to 125.

3. You want the company logo image and the company name to be arranged horizontally in
the top portion of the page. Add a layout component to accomplish that, and add the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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).

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.

Oracle University and Egabi Solutions use only


d. Drag a spacer to the af:panelFormLayout, so that the company name that you add in
the next step is not right up against the logo.
e. Drag an Output Text component to the af:panelFormLayout.
1) Set its Value to #{attrs.companyName}. (You can use the Expression Builder
and select JSP Objects > attrs > companyName.) Designers of pages that use
this template can supply a value for the companyName attribute.
2) In the Style > Text section of the Property Inspector, set Color to Blue, Size to
xx-large, Italic to italic, and Bold to bold.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

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

Oracle University and Egabi Solutions use only


name.

f. Drag a Facet Ref to the second af:showDetailItem and select tab2Content as the
facet name.
g. Drag a Facet Ref to the second facet of the af:panelSplitter and select mainContent
as the facet name. This provides a spot for page designers to place the main content of
the application.
h. Your template should look like the following:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
Use Page MainPageTemplate
Template

Oracle University and Egabi Solutions use only


6. Use the attributes of the page template to customize the page for the Storefront application.
Supply values for the attributes of the template. The company name should be Storefront
Demo and the tabs should be labeled Categories and Suppliers. The IDE does not provide
a way to use a resource bundle, so you can enter hard-coded strings in this case.
a. Set the attribute values in FODShoppingDashboard. In the editor, click the
FODShoppingDashboard tab, or reopen that file if you have closed it.
b. 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

The page should now look similar to the following:

Oracle University and Egabi Solutions use only


d. Add the company logo to the page.
1) In the page design, drag an Image component from the Component Palette to the
companyLogo facet.

2) In the Insert Image dialog box, click the arrow next to Source, click Edit, and
navigate to the \images subdirectory of your Labs main directory.
3) Select store.gif and click OK.
4) In the Image Location Problem warning box, click Yes to copy the image into the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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 >
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 >

Oracle University and Egabi Solutions use only


Refresh. You should see that the Storefront Demo text is now red.

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

Practices for Lesson 16


Chapter 16 - Page 19
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3. Add the main content. You should display the ShoppingFlow in this area.
a. From the Application Navigator, drag ShoppingFlow to the mainContent facet.

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

Oracle University and Egabi Solutions use only


you encounter.
a. Right-click the FODShoppingDashboard view activity in the adfc-config.xml task
flow and select Run. The page in the browser should look similar to the following:

b. Click the Suppliers tab. Click one of the links. You can see that the update supplier
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


d. Drag a toolbar to the toolbar facet of the panel header.
e. Drag a toolbar button to the toolbar facet and set the following properties on the
button:
Text (use the resource bundle) Shop
Action shop
The Structure window should look like this:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 17


Chapter 17 - Page 1
Chapter 17

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


Practices for Lesson 17

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 17


Chapter 17 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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-17.jws and edit the database information as described in step 4 of Practice 2-4.

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

Practices for Lesson 17


Chapter 17 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


d. Deselect Row Selection and click OK.
Note: By using the editor, JDeveloper removes the Row Selection and whatever
listeners were required. If you just remove the row selection manually in the Property
Inspector, the listeners still remain.
e. Select the SubCategory table and remove Row Selection in the same way.
2. Now you add page parameters.
Set page parameters on the ProductCatalog page to accept parameters named
param_CategoryId, param_SubCategoryId, param_CategoryName, and
param_SubCategoryName.
The page parameters should get their values from pageFlowScope variables named
CategoryId, SubCategoryId, CategoryName, and SubCategoryName.
a. Open the Page Definition for the ProductCatalog page (right-click the page and
select Go to Page Definition, or click the Bindings tab).
b. Add the following parameters to the page definition:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

The Page Definitions Parameters section should look like the following:

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

Oracle University and Egabi Solutions use only


queries based on the values that are passed to it.
Edit the bindings for the ProductCatalog page so that this method is executed upon
loading the page. Pass to the method two of the parameters that you have just defined
above.
a. Still in the page definition of the ProductCatalog page, click the Bindings and
Executables tab, then in the Bindings section, click the Create Control Binding green
plus sign and add a methodAction.
b. In the Create Action Binding dialog box, select the FODProductAMDataControl Data
Collection, and then confirm that setCurrentCategory appears in the Operation
drop-down list.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

The Parameters section of the Create Action Binding Editor should look like the

Oracle University and Egabi Solutions use only


following:

Click OK.
d. Add an InvokeAction to the Executables.

e. Set the id to invokeSetCurrentCategory and bind it to setCurrentCategory.


f. Set the Refresh property to ifNeeded.
g. Make sure that invokeAction is the first executable in the list. This ensures that the
method is executed first when the page is loaded. (If you must move it, drag it to the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


The Tree Binding editor should look like the following:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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).

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}.

Oracle University and Egabi Solutions use only


6) Insert two setActionListeners operations inside the Link with the following
properties.
From To
#{row.CategoryId} #{pageFlowScope.CategoryId}
#{row.CategoryName} #{pageFlowScope.CategoryName}
Note: You use the CategoryName and SubCategoryName parameters when
you set breadcrumbs in the next section.
c. Repeat the steps for the SubCategory table. (Make sure to pay close attention to the
pageFlowScope variable names in each setActionListener.)
1) Expand af:table - SubCategory in the second panel header.
2) Expand the first af:column node and click af:outputText for CategoryName
and copy (Ctrl + C) the Value property.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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}

Oracle University and Egabi Solutions use only


b. Select the second af:table (SubCategory) and set the Rendered property so that
the table appears if the CategoryId parameter is set but the SubCategoryId
parameter is null. (This means that the page set a category, but not a subcategory.)
The EL code is:
#{bindings.param_CategoryId ne null and
bindings.param_SubCategoryId eq null}
c. Select the third af:table - table2 (Products) and set the Rendered property so
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:
#{bindings.param_CategoryId ne null and
bindings.param_SubCategoryId ne null}
6. Modify the layout of the ProductCatalog page so that all tables are under a single panel
header whose title changes depending on the table that appears.
a. In the Structure window for the ProductCatalog page, select af:table
SubCategory in the second af:panelHeader and drag it to the first
af:panelHeader (the one currently labeled Categories).

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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:

Oracle University and Egabi Solutions use only


7. Test the page.
a. Run FODShoppingDashboard from the adfc-config task flow.
b. 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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:commandNavigationItemthe one

Oracle University and Egabi Solutions use only


labeled Store.
b. Add four setActionListeners operations with the following properties:
From To
#{null} #{pageFlowScope.CategoryId}
#{null} #{pageFlowScope.CategoryName}
#{null} #{pageFlowScope.SubCategoryId}
#{null} #{pageFlowScope.SubCategoryName}
Hint: After you add the first setActionListener, you could use the Source tab to copy,
paste, and then modify the code.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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}.
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:

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
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.

Oracle University and Egabi Solutions use only


d. Click the Add icon to add the two parameters shown above.

2. Add a method call to the shopping cart flow that calls the addItemToCart() method of
FODShoppingCartAM. Set the value of its productId argument to
#{pageFlowScope.ProductId}. Navigate to the ShoppingCart view when finished.
a. In the Data Controls panel, expand FODShoppingCartAMDataControl.
b. Drag addItemToCart(Number) to the shopping cart flow diagram.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
c. Create two Control Flow Cases from ChooseAction: one to addItemToCart named
add, and the other to ShoppingCart named display.

Oracle University and Egabi Solutions use only


d. Add two expressions to the ChooseAction router that evaluate
pageFlowScope.Action. If the value is Add, use the add outcome. If it is Display,
use the display outcome. Hint: The add expression is:
#{pageFlowScope.Action == 'Add'}
Note: The ChooseAction property is in the Cases section on the General tab of the
Property Inspector.
e. Set the display outcome to be the default outcome of the router.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only


Action Add
ProductId #{requestScope.ProductId}
The ShoppingFlow is now set up to send the Action parameter and, if needed, to
send the ProductId as well.
5. Finally, you must get the productId from the calling page and put it into the requestScope
variable ProductId. The call to add the item to the cart should be placed on the
ProductDetails page. Hint: There is currently no binding for ProductId.
a. Open the ProductDetails page fragment.
b. Add a button to the toolbar of the panel headers toolbar facet and label it Add Item
to Cart. Set its Action to add.
c. Add a binding for ProductId.
1) Click the Bindings tab.

2) In the Bindings section, click Add .


3) Add an attributeValues binding whose Data Source is
FODProductAMDataControl.BrowseProduct and whose Attribute is
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

values in the To and the From properties.

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

Oracle University and Egabi Solutions use only


ShoppingFlow, when selecting the AddShoppingCart task flow call, the Input Parameters
are correctly set to the following values:

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

Practices for Lesson 17


Chapter 17 - Page 16
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Select Parameters in the Property Inspector.

d. Click Add to add the parameter shown above.

2. Add a method call to the ManageSupplierFlow task flow to call the CreateInsert operation
for a new supplier and connect it to the SupplierUpdate activity when finished.
a. Open the ManageSupplierFlow task flow.
b. In the Data Controls panel, expand FODSupplierAMDataControl > Supplier1 >
Operations and drag the CreateInsert operation to the task flow diagram to create a
method call activity.
c. Change fixed-outcome of the CreateInsert method call activity to done.
d. Drag a Control Flow Case from CreateInsert to SupplierUpdate. from-outcome
should default to done.
3. Set up the task flow so that a new supplier is created when a parameter passed to it has a
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Set the update outcome to be the default outcome of the router.

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.

Oracle University and Egabi Solutions use only


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
default because you have set it on the ManageSupplierFlow task flow, so just set its
value in the task flow call activity.)
Name Value

SupplierAction #{requestScope.SupplierAction}

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 headers 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. Add a setActionListener to the SupplierId link.

Oracle University and Egabi Solutions use only


f. Set the From property to #{'Update'}. Set the To value to
#{requestScope.SupplierAction} to Update when the link is clicked.
6. Finally, change the panel header text of the SupplierUpdate page to conditionally display
either Update Supplier or New Supplier, depending on the value of the parameter that is
passed.
a. On the SupplierUpdate page, select the panel header.
b. If you are not using resource bundle for text, change the Text to the expression
#{pageFlowScope.SupplierAction == 'New' ? 'New Supplier' :
'Update Supplier'} (all on one line.)
c. If you are using a resource bundle for text:
1) You must make some entries to the resource bundle: Although you can edit it
directly, it may be easier to change the Display to Update Supplier, using the
resource bundle (use UPDATE_SUPPLIER_TITLE as the key), and save it. Then
change it again to New Supplier, using the resource bundle (use
NEW_SUPPLIER_TITLE as the key).
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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

Oracle University and Egabi Solutions use only

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

Practices for Lesson 17


Chapter 17 - Page 20
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 18


Chapter 18 - Page 1
Chapter 18

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


Practices for Lesson 18

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 18


Chapter 18 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


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
parameters on the ShoppingFlow, and then you enable the category tree to pass parameters
(through the use of a bean) to the Shopping flow. You use a contextual event to coordinate this
interaction between the regions on the main page.
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-18.jws and edit the database
information as described in step 4 of Practice 2-4.

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

Practices for Lesson 18


Chapter 18 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


a. Select the ShoppingFlow in the Application Navigator.
b. Select the task-flow-definition ShoppingFlow node in the Structure window.

c. Use the Parameters section of the Property Inspector to create the following input
parameters:
Name Value
CategoryId #{pageFlowScope.CategoryId}
CategoryName #{pageFlowScope.CategoryName}
SubCategoryId #{pageFlowScope.SubCategoryId}
SubCategoryName #{pageFlowScope.SubCategoryName}
The Property Inspector should look like the following:

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.)

Oracle University and Egabi Solutions use only


package oracle.storefront.ui.common;

import java.util.Map;

import javax.el.ELContext;
import javax.el.Expression;
import javax.el.ExpressionFactory;
import javax.el.MethodExpression;
import javax.el.ValueExpression;

import javax.faces.context.FacesContext;
import oracle.adf.model.BindingContext;
import oracle.adf.model.DataControlFrame;

/**
* 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

*/
public static void saveAndContinue() {
Map sessionMap =

FacesContext.getCurrentInstance().getExternalContext().getSessio
nMap();
BindingContext context =

(BindingContext)sessionMap.get(BindingContext.CONTEXT_ID);
String currentFrameName =
context.getCurrentDataControlFrame();
DataControlFrame dcFrame =

Oracle University and Egabi Solutions use only


context.findDataControlFrame(currentFrameName);

dcFrame.commit();
dcFrame.beginTransaction(null);
}

/**
* Programmatic evaluation of EL.
*
* @param el EL to evaluate
* @return Result of the evaluation
*/
public static Object evaluateEL(String el) {
FacesContext facesContext =
FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

*/
public static Object invokeEL(String el) {
return invokeEL(el, new Class[0], new Object[0]);
}

/**
* 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

Oracle University and Egabi Solutions use only


* @param params Array of Object defining the values of the
* parametrs
* @return Object that the method returns
*/
public static Object invokeEL(String el,
Class[] paramTypes, Object[] params) {
FacesContext facesContext =
FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =

facesContext.getApplication().getExpressionFactory();
MethodExpression exp =
expressionFactory.createMethodExpression(elContext,
el, Object.class, paramTypes);
return exp.invoke(elContext, params);
}

/**
* 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =

facesContext.getApplication().getExpressionFactory();
ValueExpression exp =
expressionFactory.createValueExpression(elContext,
el, Object.class);
exp.setValue(elContext, val);
}
}

Oracle University and Egabi Solutions use only


6. Right-click anywhere in the code editor and select Make to compile the class.

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

Practices for Lesson 18


Chapter 18 - Page 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


e. Add private variable definitions for the following:
categoryId, subCategoryId (Number)
categoryName, subCategoryName (String)
At this point, the code should be:
public class FODCategoryBean {
private Number categoryId, subCategoryId;
private String categoryName, subCategoryName;

public FODCategoryBean() {
super();
}

f. Generate accessors for these variables using either the toolbar button (on the
visual editor pane) or the menu Source > Generate Accessors. Click the select all
button. Click OK to generate the accessors.
2. Add a method named onNodeClicked() that returns a bean with values set based on the
values of the node that the user clicked: (You can copy it from onNodeClicked.txt in the
\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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Number categoryId, subCategoryId;


String categoryName, subCategoryName;
if (parentRow == null) {
// Root category selected
categoryId =
(Number)nodeRow.getAttribute("CategoryId");
categoryName =
(String)nodeRow.getAttribute("CategoryName");
subCategoryId = null;
subCategoryName = null;

Oracle University and Egabi Solutions use only


} else {
// Sub-category selected
categoryId =
(Number)parentRow.getAttribute("CategoryId");
categoryName =
(String)parentRow.getAttribute("CategoryName");
subCategoryId =
(Number)nodeRow.getAttribute("CategoryId");
subCategoryName =
(String)nodeRow.getAttribute("CategoryName");
}

setCategoryId(categoryId);
setSubCategoryId(subCategoryId);
setCategoryName(categoryName);
setSubCategoryName(subCategoryName);

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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,
click the Refresh icon on the Application Navigator.
The Data Control panel should look something like the following:

Oracle University and Egabi Solutions use only

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

Practices for Lesson 18


Chapter 18 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Click OK to accept the default values on the Confirm Component Rebinding page.
2. Add an event to the page named FODSelectCategory that will be registered when the user
clicks the node.
a. While still on the ProductCategory page, click the Bindings tab.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d. Insert an event inside the event list and set the name property to
FODSelectCategory.

The Binding Structure should look like the following:

Oracle University and Egabi Solutions use only


You now have specified that clicking a node at run time in the Category Tree calls the
onNodeClicked() method and raises the FODSelectCategory event.

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

Practices for Lesson 18


Chapter 18 - Page 13
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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:
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.

Oracle University and Egabi Solutions use only


2. Add the refreshCategory() method. This method uses an ADFUtil method to set the
requestScope variables to hold the category and subcategory ID and name: (You can
copy it from refreshCategory.txt in the \files subdirectory of the Labs directory.)
/**
* Used as a consumer to a contextual event, changes the
* parameter values passed to the local area region and forces
* a refresh in that area.
*
* @param category Selected category
*/
public void refreshCategory(FODCategoryBean category) {
/*
* For the selected category, set requestScope
* variables.
* These variables are used as parameters to the local
* area region.
*/
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

ADFUtil.setEL("#{requestScope.refreshLocalArea}",
Boolean.TRUE);
}
3. JDeveloper prompts you to import the supporting package. Import the following:
oracle.storefront.ui.common.ADFUtil;
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:

Oracle University and Egabi Solutions use only

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

Practices for Lesson 18


Chapter 18 - Page 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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 parameters value blank.

Oracle University and Egabi Solutions use only


d. Click OK to create the binding.
2. Create an event map to orchestrate the contextual event.
a. On the Bindings tab for FODShoppingDashboard, right-click the top-level node in
the Structure window and select Edit Event Map.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

1) From the Producer drop-down list, select FODShoppingDashboardPageDef >


ProductCategoryFlow1 > ProductCategoryPageDef.onNodeClicked.

2) Select FODSelectCategory as the Event Name. (This should be selected by

Oracle University and Egabi Solutions use only


default, because it is the only event that you have defined.)
3) Select FODShoppingDashboardPageDef > refreshCategory from the
Consumer drop-down list.

4) In the Consumer Params section, click Add Consumer Parameter to define


a parameter named category with a value of #{payLoad}. (You can use the
Expression Builder to select Payload Data > payLoad.) Click OK.

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

Practices for Lesson 18


Chapter 18 - Page 17
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d. Click OK to create the event mapping in the containing FODShoppingDashboard page.

Oracle University and Egabi Solutions use only


e. Click OK again.

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

Practices for Lesson 18


Chapter 18 - Page 18
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


FODShoppingDashboard bean is to set a Boolean requestScope variable named
refreshLocalArea to true. Set a refresh condition in the ShoppingFlow region to make
use of the value of this variable, so that the region is refreshed only if refreshLocalArea
is set to true.
a. Still in the FODShoppingDashboard page definition (the Binding tab of the page),
select Executables > ShoppingFlow1 in the Structure window.
b. Set RefreshCondition to #{requestScope.refreshLocalArea}.

2. Set region parameter values to the requestScope values that are set by the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 18


Chapter 18 - Page 20
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


d. On the Hierarchy tab of the Implement Interface dialog box, select javax > faces >
event > PhaseListener and click OK.

e. Add a private String attribute named storedViewId to store the view ID by adding
the following on the line just after the first left brace:
private String storedViewId = null;
f. Modify the getPhaseId() method to return the PhaseId of whatever life-cycle phase
being executed with the following code:
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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) {
String viewId =
phaseEvent.getFacesContext().getViewRoot().getViewId();
if (storedViewId != null &&
!viewId.equalsIgnoreCase(storedViewId)) {
System.out.println("Changing pages");
}
storedViewId = null;

Oracle University and Egabi Solutions use only


}
}
2. Register the new phase listener with JavaServer Faces.
a. Open faces-config.xml in the editor by double-clicking it in the Application
Navigator (under WebContent > WEB-INF).
b. Click the Overview tab.
c. On the Life Cycle tab, click Add to add a Phase Listener.
d. Enter the complete path to the phase listener and the class name:
oracle.storefront.ui.common.StorefrontPhaseListener.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
h. When you have finished, close the browser and undeploy the application as described
in step 6(i) of Practice 2-4.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 18


Chapter 18 - Page 23
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 18


Chapter 18 - Page 24
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 19


Chapter 19 - Page 1
Chapter 19

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


Practices for Lesson 19

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 19


Chapter 19 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


completed up to the start of this lesson, open Storefront-19.jws and edit the database
information as described in step 4 of Practice 2-4.

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

Practices for Lesson 19


Chapter 19 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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-

Oracle University and Egabi Solutions use only


outcome property to done.

2. Test the functionality:


a. Run FODShoppingDashboard from the adfc-config task flow.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


c. Make it Public and keep other default options.
2. Add a method named onDeleteItem that calls the ADFUtil.invokeEL() helper
method to execute the EL expression that you pass in as a parameter. In this case, it will
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.
a. Add the following code: (You may copy the code from onDeleteItem.txt in the
\files subdirectory of the Labs directory.)
/**
* Deletes the current selected row in the Shopping Cart.
*
* @param actionEvent
*/

public void onDeleteItem(ActionEvent actionEvent) {


ADFUtil.invokeEL("#{bindings.Delete.execute}");
ADFUtil.invokeEL("#{bindings.Commit.execute}");
}
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

4. Complete the ShoppingCart page by adding buttons for Update, Delete, and Details; these
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.

Oracle University and Egabi Solutions use only


c. Insert a toolbar inside Panel Collection facets > toolbar.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

page definition.

Oracle University and Egabi Solutions use only


e. Set the following properties on the toolbar button:
Id updateMenu
Text (optionally use Update
the resource bundle)
Action <default>
Disabled Reset to default value
f. Add a second toolbar button to the toolbar. This time add it from the Component
Palette, or right-click and select insert inside.
g. Set the following properties on the second toolbar button:
Id deleteMenu
Text (use the Delete
resource bundle)
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

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.

Oracle University and Egabi Solutions use only


e. In the Property Inspector, change the InstanceName to
FODShoppingCartAMDataControl.ShoppingCart.ShoppingCartItem1.
6. 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


7. Enable the quantity to be updated.
a. With af:table still selected, click the Edit Component Definition icon on the
Property Inspector and ensure that the Row Selection check box is selected, and click
OK.
b. Select af:outputText - #{rowQuantity} and convert it to an Input Text.

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
buttonyou 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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

a. In ShoppingCart.jsff, drag a Popup from the Component Palette to af:panelCollection


in the Structure window.

b. Set the following properties in the pop-up window:


Id ProductDetails

Oracle University and Egabi Solutions use only


ContentDelivery LazyUncached
c. Insert a Dialog in the pop-up window.
d. Drag FODShoppingCartAMDataControl > ShoppingCart1 > ShoppingCartItem1 to
af:dialog as an ADF Read-only Form.

1) Do not include Navigation Controls or a Submit button.


2) Include the following columns, in the same order:
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3) Using the Edit option, set PopupId to ProductDetails.

Oracle University and Egabi Solutions use only


10. Test the functionality.
a. When you click Details on the ShoppingCart page, the productDetails pop-up should
display the dialog box.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. Select the SubmitOrder task flow return and set the End Transaction property to
commit.
d. Select CancelOrder task flow return and set the End Transaction property to
rollback.
2. Run the FODShoppingDashboard page to test the checking out steps. When you click
Submit on the Confirmation page, any changes you have made to the shipping and billing
information are committed. In a real SOA-integrated application, this could, for example,
commit an order and start some back-end processing.

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

Practices for Lesson 19


Chapter 19 - Page 12
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. In the Property Inspector, click the Behavior tab and set transaction to Always Begin
New Transaction.
d. In the editor, select the Save task flow return and set its End Transaction property to
commit.
e. In the editor, select the Cancel task flow return and set its End Transaction property
to rollback.
f. Save your work.
2. Add the ability to delete a supplier to the BrowseSuppliers page fragment.
a. Open the BrowseSuppliers page fragment in the editor.
b. Check whether the table has row selection enabled by selecting af:table in the
Structure window, and then clicking Edit in the Property Inspector. Ensure that the
Row Selection check box is selected.
c. In the Data Control panel, expand FODSupplierAMDataControl > Supplier1 >
Operations and drag the Delete operation to the toolbar in the toolbar facet of the
Panel Header on the page, creating an ADF Toolbar Button.

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

Practices for Lesson 19


Chapter 19 - Page 13
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d. Set the following properties on the button:


Id deleteSupplier
ActionListener Set to the onDeleteItem method of the
managed bean (Use the method expression
builder from the list to select it.)

Oracle University and Egabi Solutions use only


e. The onDeleteItem() method calls bindings.Delete.execute and
bindings.Commit.execute. When you added the delete operation as a button, the
Delete binding was added, but there is no Commit binding. Add a Commit binding to
the page definition.
1) Click the Bindings tab.

2) In the Bindings section, click Create control binding .


3) In the Insert Item dialog box, select action and click OK.
4) In the Create Action Binding dialog box:
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


h. Save your work.
3. Test the functionality.
a. Run FODShoppingDashboard from the adfc-config task flow.
b. Click the Suppliers tab and resize the left panel of the panel splitter until you can see
the New Supplier and Delete buttons.
c. Select the supplier that you previously added and click Delete. You should see that the
supplier is removed from the row.
d. Close the browser. In the JDeveloper log pane, click the Target URL link to rerun the
page.
e. Click the Suppliers tab. You should see that the supplier you deleted is no longer in
the table even when the data is required.
f. When 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 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 19


Chapter 19 - Page 16
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 20


Chapter 20 - Page 1
Chapter 20

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


Practices for Lesson 20

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 20


Chapter 20 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


information as described in step 4 of Practice 2-4.

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

Practices for Lesson 20


Chapter 20 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


2. Invoke the Configure ADF Security Wizard and configure the application to use ADF
security for both authentication and authorization.
a. With the StorefrontUI project selected in the Application Navigator, from the main
menu, select Application > Secure > Configure ADF Security.
b. On the ADF Security page of the wizard, select the ADF Authentication and
Authorization option, and then click Next.
c. On the Authentication Type page of the wizard, select the Form-Based
Authentication option and the Generate Default Pages check box. Click Next.
d. On the Automatic Policy Grants page of the wizard, select the No Automatic Grants
option, and then click Next.
e. On the Authenticated Welcome page, select Redirect upon successful
authentication, and on the welcome page, select the
/oracle/storefront/ui/pages/FODShoppingDashboard.jspx page. Click
Next.
f. The Summary page of the wizard displays a list of files that will be changed or created.
Click Finish to create the security configuration.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

4. If you look in the file system, you can compare the modified dates to see which files have
been changed.

Oracle University and Egabi Solutions use only


a. First, using Windows Explorer, look in the Storefront-20 > .adf > META-INF
subdirectory of your application resource descriptor. You could see that the adf-
config.xml file has just been changed.
b. Next, look in the Storefront-20 > src > META-INF subdirectory of your application
resource descriptor. You should see that all files except for weblogic-
application.xml have been changed.
c. Finally, look in the StorefrontUI > public-html > WEB-INF subdirectory of your
application. You can see that web.xml and weblogic.xml have been changed.
(Actually, weblogic.xml is a new file.)

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

Practices for Lesson 20


Chapter 20 - Page 5
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d. The Application Navigator displays the corresponding files.

Oracle University and Egabi Solutions use only


e. Note that the changed files are the ones that the Summary page of the Configure ADF
Security Wizard reported to be created or changed.
5. In the JDeveloper Application Resources panel, double-click jazn-data.xml to open it,
and then click the Source tab to examine the entries. It is a newly created file that contains:
The default realm name for the optional XML identity store
The policy store for the Storefront-20 application, consisting of application roles and a
policy. The policy grants permissions on resources (task flows and pages) to the
application roles.
6. Similarly, using the Source tab, examine:
a. jps-config.xml: Definitions have been added for service providers, service
instances, and the context for Java Platform Security.
b. adf-config.xml: The JaasSecurityContext entry has been added, specifying
that both authentication and authorization are enforced.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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).

Oracle University and Egabi Solutions use only


d. Repeat steps b and c for each user; the users appear in the Users list. Instead of
pgamer, you can add your own name if you would prefer to.

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

Practices for Lesson 20


Chapter 20 - Page 7
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


1. Create the enterprise roles manager, clerk, customer, and developer.

a. Click the Enterprise Roles tab, and then click Add in the Roles panel.
b. In the Add Role dialog box, enter the Name manager.
c. Repeat steps a and b to add the other three roles; the roles appear in the Enterprise
Roles list along with the test-user role that the security configuration created.

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

Practices for Lesson 20


Chapter 20 - Page 8
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

2. Add the following users to the enterprise roles:


manager sking
clerk bernst
customer DRAPHEAL (use this exact name)
developer pgamer (or your own name if you created it as a user)
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.

Oracle University and Egabi Solutions use only


e. Repeat steps b, c, and d for each role indicated above.
3. Create application roles that correspond to the identity store roles (manager, clerk,
customer, and developer) prefixed by fod_, such as fod_customer. Also create a
fifth application role called fod_user.
a. Select Application Roles at the left, and then click the Add icon in the Application
Roles panel.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


e. Then add clerk, customer, manager, and developer to fod_user.

5. Save your work.

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

Practices for Lesson 20


Chapter 20 - Page 10
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
Add Application Role .

Oracle University and Egabi Solutions use only


c. In the Select Roles dialog box, select the check boxes for fod_manager, fod_clerk,
and fod_developer, and then click OK.
Note: If all the roles do not appear in the Select Roles dialog box, close jazn-
data.xml and reopen it. The roles should then appear.

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

Practices for Lesson 20


Chapter 20 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

d. By default, each selected role is assigned with the View Action. Keep this option
selected.

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.

Oracle University and Egabi Solutions use only


c. If necessary, delete the test-all role.
d. Repeat steps a and b for CheckoutFlow and ShoppingFlow.

3. Grant all roles access to displaying the following flows.


a. Select ShowSuppliersFlow.
b. Add the fod_user application role.
c. If necessary, delete the test-all role.
d. Repeat steps a and b for ProductCategoryFlow.
4. Ensure that all users can access the FODShoppingDashboard page.
a. Click the Web Pages tab.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


The error page should display the message:

Note: When using Internet Explorer, you may receive an HTTP error instead of seeing
the error page.
2. Test authorization.
a. Click the browsers Back button.
b. On the login page, enter the username sking, a valid user who is not authorized to
use the shopping application. Enter the password welcome1, and then click Submit.
The FODShoppingDashboard page appears, but the shopping application is not
visible. You see data only when you click the Suppliers tab.
Note: If you encounter an error when you enter the login information after using the
Browsers Back button, rerun the application.

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

Practices for Lesson 20


Chapter 20 - Page 13
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


g. When 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 20


Chapter 20 - Page 14
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


c. In the Edit Security dialog box, enable security on all operations, and then click OK.

d. In the Structure window, right-click SupplierEO and select Edit Authorization.

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

Practices for Lesson 20


Chapter 20 - Page 15
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

e. In the Edit Authorization dialog box, grant the following privileges:

Privileges Roles
Read fod_user
Update fod_clerk, fod_developer, fod_manager
Delete fod_clerk, fod_developer

Oracle University and Egabi Solutions use only


f. Click OK.

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

Practices for Lesson 20


Chapter 20 - Page 16
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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
is disabled. However, when you click New Supplier, or when you click a supplier ID
link, you should be able to navigate to the New Supplier or the Update Supplier
window.
f. Close the browser and click the target URL in the Running Log pane to relaunch the
application in your browser.
g. This time log in as bernst, who has the clerk role, or as pgamer, who has the
developer role. Click the Suppliers tab. You should see that the Delete button is
now enabled. Also, when you click New Supplier, or when you click a supplier ID link,
you should be able to navigate to the New Supplier or the Update Supplier window.
h. Close the browser and undeploy the application.

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

Practices for Lesson 20


Chapter 20 - Page 17
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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();

Oracle University and Egabi Solutions use only


}
b. Press Alt + Enter if prompted to import oracle.adf.share.ADFContext.
3. Add a method to determine whether the user is in a certain role.
a. Add the following code just above the closing right brace:
public boolean isUserInRole(String role) {
return
ADFContext.getCurrent().getSecurityContext().isUserInRole(role);
}
b. Expose the added methods to the client interface of FODShoppingCartAM application
module.
1) In the Application Navigator, double-click FODShoppingCartAM to open it in the
editor.
2) Click the Java tab.
3) In the Client Interface section, click Edit .
4) In the Edit Client Interface dialog box, shuttle getUserName():String and
isUserInRole(String):boolean from the Available list to the Selected list, and
then click OK.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. In the JAAS Security login dialog box, enter DRAPHEAL as Principal and welcome1 as
Credentials, and then click OK.

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.

Oracle University and Egabi Solutions use only


e. Select isUserInRole from the Method drop-down list and enter customer as the
Value. Click Execute. You should see the Return value of true.
f. Change the Value to manager and click Execute. The Return value should be false.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


property to #{!securityContext.userInRole['fod_customer']}.

2. Test the new functionality:


a. Run the Start page and log in as a customer (DRAPHEAL). Click the Suppliers
tabthe New Supplier button should not appear.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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).

Oracle University and Egabi Solutions use only


b. Open or switch to BrowseSuppliers.jsff in the editor.
c. Click the New Supplier button and set the Rendered property to
#{securityContext.taskflowViewable['']}, and then paste the complete
task flow name between the single quotation marks.

4. Ensure that the button appears if authentication security is not enabled. Instead of using a
global security expression, write a security proxy bean to check the security. Name the
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

return
(ADFContext.getCurrent().getSecurityContext().isAuthorizationEna
bled());
}
}
b. Register FODSecurityBean as a managed bean:
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

Oracle University and Egabi Solutions use only


Name FODSecurityBean
Class oracle.storefront.ui.bean.FODSecurityBean
Scope request

5) On the BrowseSuppliers page fragment, change the Rendered property of the


New Supplier button to the following expression:
#{FODSecurityBean.authorizationEnabled ?
securityContext.taskflowViewable['/WEB-
INF/oracle/storefront/ui/flow/ManageSupplierFlow.xml#ManageSu
pplierFlow'] : true}

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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().

Oracle University and Egabi Solutions use only


d. Delete the commented TODO lines.
e. Add a clause that sets the userPrincipal variable to the hard-coded string if
security is not implemented. Change the line:
String userPrincipal = getUserName();
to
String userPrincipal;
if
(ADFContext.getCurrent().getSecurityContext().isAuthorizationEna
bled())
userPrincipal = getUserName();
else
userPrincipal = "DRAPHEAL";

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

Practices for Lesson 20


Chapter 20 - Page 23
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


d. Double-click ShoppingCart1 and click Cancel in the Bind Variables dialog box to
accept the values that were set in the init() method.
e. The shopping cart for DRAPHEAL should be shown.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only

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

Practices for Lesson 20


Chapter 20 - Page 25
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Lesson 20


Chapter 20 - Page 26
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Appendix A


Chapter 21 - Page 1
Chapter 21

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


Practices for Appendix A

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Appendix A


Chapter 21 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only

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

Practices for Appendix A


Chapter 21 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


c. Expand the FOD node to view the types of database objects that the schema contains.
2. Create a new database diagram named FODSchema and put it in the
oracle.fod.storefront.design package.
a. In the Application Navigator, right-click the StorefrontModel project and select New
from the context menu.
b. In the New Gallery:
i) Expand the General node if it is not already expanded.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Oracle University and Egabi Solutions use only


iv) Click OK.
c. In the Create Database Diagram dialog box:
i) Change the name of your diagram to FODSchema.
ii) Change the package to oracle.fod.storefront.design.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

b. Use Ctrl-click to multiselect the Orders and Order_Items tables and drag them to the
diagram surface.

Oracle University and Egabi Solutions use only


c. In the Specify Location dialog box, change the offline database name to FodDB, and
then click OK to copy the database objects to the new offline database in your project
and to place them on your diagram.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

diagram should look something like the following screenshot.

Oracle University and Egabi Solutions use only


e. You can modify the column information in the diagram, although you should not modify
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

3) Set Precision to 10.


4) Make sure that Shipper_Id is a mandatory column by selecting the Cannot be
NULL check box.

Oracle University and Egabi Solutions use only


5) Similarly, add a Shipper_Name column, with the default values for data type and
size. This is not a mandatory column.
6) In the list at the left of the Edit Table dialog box, select Primary Key and set the
primary key as follows:
a) Select SHIPPER_ID in the Available Columns list.

b) Click Add to shuttle SHIPPER_ID to the Selected Columns list.


7) Click OK. The diagram should look similar to this:

2. Generate the DDL for adding the new table to the database, but do not actually add the
table.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


3) Select the SQLScript option on the Specify Target page, and click Next.
4) The Object Picker page should show SHIPPERS in the Selected list. Click Next.
5) On the Choose Operation page, select the Create option and click Next.
6) On the SQL Script Options page, change the name of the SQL file to
CreateShippersTable.sql and click Next.
7) Click Finish to generate the script.
c. When the wizard is complete, the script file opens in the editor. Note the three tabs:
Source, SQL worksheet, and History. Examine the file contents.
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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Appendix B


Chapter 22 - Page 1
Chapter 22

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


Practices for Appendix B

Oracle University and Egabi Solutions use only


THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

Practices for Appendix B


Chapter 22 - Page 2
Copyright 2010, Oracle and/or its affiliates. All rights reserved.
Oracle University and Egabi Solutions use only
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


Practice 2-4.

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

Practices for Appendix B


Chapter 22 - Page 3
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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

Oracle University and Egabi Solutions use only


myStorefrontUI and click OK.
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. Click OK twice.
2. Create a deployment profile named myStorefront for the application, specifying that it
should contain the myStorefrontUI WAR file and the JAR file for the StorefrontModel
project.
a. Invoke the Application menu and select Application Properties.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
StorefrontModelArchive check boxes, and then click OK twice.

Oracle University and Egabi Solutions use only

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

Practices for Appendix B


Chapter 22 - Page 5
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


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
item Start Admin Server for WebLogic Server Domain. After the server has started,
you can minimize the startWebLogic command window.
b. Log in to the Administration Server Console with the username of weblogic and the
password of weblogic.
c. In the Domain Structure menu at the left of the window, expand the Services and
JDBC nodes, and then click the Data Sources node.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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
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.

Oracle University and Egabi Solutions use only


a. In the JDeveloper Application Navigator, right-click the FODCategoryAM application
module and select Configurations.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

a. In the Application Navigator, select DataBindings.cpx in the StorefrontUI project.

Oracle University and Egabi Solutions use only


b. In the Structure window:
1) Expand DataBindings > dataControlUsages.
2) Select each application module data control usage, and in the Property Inspector,
set its Configuration to be the Web configuration that you just defined, such as
FODProductAMWeb.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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

Oracle University and Egabi Solutions use only


Connection Name myWLS
Password weblogic
Deploy Password Checkbox selected
Port 7001
WLS Domain myWLS_domain
d. On the last page of the wizard, click Test, and then click Finish if the connection is
successful.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.

Oracle University and Egabi Solutions use only


The log window displays deployment messages. It may take a few minutes to finish the
deployment; wait until the window displays the message that the deployment is
finished.

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
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only

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

Practices for Appendix B


Chapter 22 - Page 11
THESE eKIT MATERIALS ARE FOR YOUR USE IN THIS CLASSROOM ONLY. COPYING eKIT MATERIALS FROM THIS COMPUTER IS STRICTLY PROHIBITED

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.
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.

Oracle University and Egabi Solutions use only


c. In the Deployments panel, click Install.
d. By clicking through the displayed directories, locate the myStorefront.ear file in the
directory where it was created and select it, and then click Next.

e. Select the Install this deployment as an application option and click Next.
f. Select the Copy this application onto every target for me option and click Next.
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