Vous êtes sur la page 1sur 399

Oracle JDeveloper 10g: Build

Applications with ADF


Electronic Presentation

D16975GC10
Production 1.0
May 2004
D39416

Author

Copyright 2004, Oracle. All rights reserved.

Gary Williams
Lynn Munsinger
Patrice Daux

This documentation contains proprietary information of Oracle Corporation. It is provided under a


license agreement containing restrictions on use and disclosure and is also protected by copyright
law. Reverse engineering of the software is prohibited. If this documentation is delivered to a U.S.
Government Agency of the Department of Defense, then it is delivered with Restricted Rights and the
following legend is applicable:

Technical Contributors and


Reviewers
Jeff Gallus
Pam Gamer
Duncan Mills
Publisher
Joseph Fernandez

Restricted Rights Legend


Use, duplication or disclosure by the Government is subject to restrictions for commercial computer
software and shall be deemed to be Restricted Rights software under Federal law, as set forth in
subparagraph (c)(1)(ii) of DFARS 252.227-7013, Rights in Technical Data and Computer Software
(October 1988).
This material or any portion of it may not be copied in any form or by any means without the express
prior written permission of the Education Products group of Oracle Corporation. Any other copying is
a violation of copyright law and may result in civil and/or criminal penalties.
If this documentation is delivered to a U.S. Government Agency not within the Department of
Defense, then it is delivered with Restricted Rights, as defined in FAR 52.227-14, Rights in DataGeneral, including Alternate III (June 1987).
The information in this document is subject to change without notice. If you find any problems in the
documentation, please report them in writing to Worldwide Education Services, Oracle Corporation,
500Oracle Parkway, Box SB-6, Redwood Shores, CA 94065. Oracle Corporation does not warrant
that this document is error-free.
Oracle and all references to Oracle Products are trademarks or registered trademarks of Oracle
Corporation.
All other products or company names are used for identification purposes only, and may be
trademarks of their respective owners.

Introduction

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this course, you should be able to do


the following:
Design and implement business services by using
Oracle ADF Business Components
Generate and test the end-to-end components as a
complete ADF application
Build Web-based views for an application, using
declarative tools in Oracle JDeveloper 10g
Use Oracle JDeveloper 10g to define user interface
functionality and application flow based on Struts

I-2

Copyright 2004, Oracle. All rights reserved.

Course Overview

This course teaches:


How to build J2EE applications by using Oracle
JDeveloper 10g
How to build and implement business services by
using Oracle ADF Business Components
How to build MVC-based client application
components
How to use Struts as the controller in an MVCbased application

I-3

Copyright 2004, Oracle. All rights reserved.

Oracle Application Development


Framework

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Describe the Java 2, Enterprise Edition (J2EE)
platform
Describe the benefits of framework-based
application development
Describe the purpose and benefits of Oracle ADF
Describe the Model-View-Controller (MVC)
architecture
Describe the technologies used in each of the
MVC layers

1-2

Copyright 2004, Oracle. All rights reserved.

J2EE Platform

Is a multitiered, distributed application model


Supports component-based J2EE applications

Client Machine

1-3

J2EE Server

Database Server

Client tier

Web tier

Business tier

EIS tier

Browser/
Application

JSP/
Servlet

Business
Services

Database

Copyright 2004, Oracle. All rights reserved.

Benefits of the J2EE Platform

Write once, run anywhere provides simplified


component development.
J2EE separates client requirements from business
logic.
J2EE provides multiple development and design
scenarios:
Multitier
Web
Stand-alone client

1-4

J2EE separates development tasks into specific


skill areas.

Copyright 2004, Oracle. All rights reserved.

J2EE Platform: Architecture Details


Client Machine
Browser

Client
container
Application
Client

J2EE Server
Business
Web
container
container

JSP/
Servlet

Business
Services

JNDI

RMI

JTA

JDBC

JMS

JavaMail

JAF
APIs

1-5

Copyright 2004, Oracle. All rights reserved.

EIS tier

Database

Building J2EE Applications

1-6

Building J2EE applications can be complex.


Development time can be extensive.
Choosing and implementing appropriate design
patterns can be overwhelming.
Do it yourself applications often repeat existing
application code.
A large portion of Do it yourself code is
dedicated to common tasks.
The more code you write, the greater is the chance
of errors.
Using an existing application framework enables
you to concentrate on your business needs.
Copyright 2004, Oracle. All rights reserved.

What Is Framework-Based
Application Development?
A framework:
Is a productivity layer for building applications
Is a set of intelligent cooperating software
components
Is designed to be specialized for your business
Handles the majority of common tasks with
sensible behavior
Enables easy customization of default behaviors
Uses standard, proven techniques and design
patterns

1-7

Copyright 2004, Oracle. All rights reserved.

Understanding Framework-Based
Application Development
Provides hook points
to standard functions

Framework

You can augment


or circumvent
base functionality.

Your objects have


only your code.

A framework provides base


functionality:

1-8

Standard behaviors
Data access methods
Transaction management

No messy code
generation

Copyright 2004, Oracle. All rights reserved.

Oracle Application Development


Framework

Reduces the complexity of J2EE development by


providing visual and declarative development
Increases development productivity
Less coding, more reuse
Focus on the application, not the plumbing

1-9

Encourages J2EE best practices by implementing


standard J2EE design patterns (MVC)
Provides a flexible and extensible environment by
allowing multiple technology choices and
development styles

Copyright 2004, Oracle. All rights reserved.

Visual and Declarative Development

Visual
WYSIWYG editors
UML modelers
Structure pane

Declarative
Structure pane
Property Inspector

Code view/design view synchronization


No separate generation stepalways synchronized
Underlying code always accessible

1-10

Copyright 2004, Oracle. All rights reserved.

Design Patterns

Design patterns:
Are proven solutions to specific problems
Are a means to an end, not the end itself
Address programming tasks, not business
problems
Are reusable
Provide a framework for re-creatable results

1-11

The MVC architecture is an example of a design


pattern.

Copyright 2004, Oracle. All rights reserved.

Model-View-Controller Architecture
MVC provides logical separation of an application.
Client
tier

Web
tier

Browser/
Application

Model

Business Services

Controller

Business
tier

View

1-12

Copyright 2004, Oracle. All rights reserved.

EIS
tier

Database

MVC Structure
Controller
Handles routing to the
correct page
Maps UI data changes
to the Model

Display

1-13

Submit
page

Data and
transactions

View

Model

Renders the UI
Requests data from the
Model
Sends Events to the Model
Allows the Controller to
select the next View

Stores the application


state
Responds to data requests
Encapsulates business
logic

Request
data

Copyright 2004, Oracle. All rights reserved.

What Is the Model?

It is a wrapper and abstraction for business


services:
Handles data events from the Controller
Feeds data to the View

It manages and presents data from different


Business Service types in a common way.

View

Controller
Model

1-14

Copyright 2004, Oracle. All rights reserved.

The Model Layer


Model

ADF Bindings
ADF Data Control

Business
Services

EJB
Session
Beans

Java
Classes

JDBC

TopLink
Queries

Java
Classes

ADF
Application
Module

EJB
Finders

ADF
View Object

EJB Entity
Beans

TopLink Mapping

1-15

Copyright 2004, Oracle. All rights reserved.

ADF
Entity
Object

Web
Services

Components of the Model Layer

Bindings:
Metadata that describes how the UI components on
a page use the values and actions provided by the
Business Service

Data controls:
Metadata that describes the data model returned by
the Business Service

The metadata has the same format for all business


services.
ADF Bindings
ADF Data Control

1-16

Copyright 2004, Oracle. All rights reserved.

What Is the Controller?

On a Web page, everything significant


happens on submit or a link.
A Controller intercepts a request and
dispatches it to the correct page.
The source page does not have to know how to
handle an event or where to go next.
The handling code does not need to know what
page to display in response.
The Controller separates the Model and the View.
The Controller manages the flow of a Web
application.

1-17

Copyright 2004, Oracle. All rights reserved.

Struts in JDeveloper

JDeveloper uses Apache Struts as a Controller.


It is popular among J2EE developers.
It has been around since 2000.
It is designed to handle views based on HTTP
technology.

1-18

Copyright 2004, Oracle. All rights reserved.

Controller: Summary

1-19

Controllers are key to MVC separation


and to promote code and layer reuse.
Apache Struts is the de facto standard for
Web application controllers.
Oracle JDeveloper 10g supports Struts as a
controller.

Copyright 2004, Oracle. All rights reserved.

What Is the View?

The MVC View is the UI of the application.


It is what the end user sees and interacts with.

View

Controller

Model
1-20

Copyright 2004, Oracle. All rights reserved.

View Concept

1-21

A View does not contain application


code; it contains code to represent
the UI and pass events to the Controller.
Views are interchangeable without rewriting
controller or model logic.
A single application can have different Views that
are compatible with different types of devices
(HTML browser, handheld devices, and so on).

Copyright 2004, Oracle. All rights reserved.

View Technologies in
Oracle JDeveloper 10g
JavaServer Pages (JSP)
UIX
ADF JClient
Creating databound clients is the same in JDeveloper
for any of these supported client technologies.

1-22

Copyright 2004, Oracle. All rights reserved.

View: Summary

1-23

Views contain only display code.


Views do not contain application logic.
Views do not contain navigation logic.
Views are independent of the Controller and the
Model.

Copyright 2004, Oracle. All rights reserved.

ADF Technology Stack

View

JSP

Controller

1-24

JSF

Swing/
ADF JClient

Struts

ADF Model

Model

Business
Services

ADF UIX

ADF
Business
Components

EJB
Session
Beans

Web
Services

Copyright 2004, Oracle. All rights reserved.

JavaBeans/
Other

ADF: Summary

Productive end-to-end development


Model-View-Controller
Visual
Declarative

Standard J2EE framework

1-25

Implements J2EE best practices


Uses the latest standards
Provides architecture choices
Is built on the MVC design pattern

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Identify the benefits of framework-based
application development
Describe the Java 2, Enterprise Edition (J2EE)
platform
Define the components of the Model-ViewController architecture
Describe the benefits of Oracle Application
Development Framework (ADF)
Describe the technologies used in each of the
MVC layers

1-26

Copyright 2004, Oracle. All rights reserved.

ADF Development Process

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Identify the typical process cycle for developing
an ADF application
List the main design-time features used to build
ADF applications
Use the course application to query products and
to perform a transaction

2-2

Copyright 2004, Oracle. All rights reserved.

Project Technology Scopes

2-3

ADF is a design-time and run-time framework for


J2EE applications.
JDeveloper provides design-time tools to support
J2EE development.
There are numerous technology stacks available
for J2EE application development.
The choice is yours.

Copyright 2004, Oracle. All rights reserved.

ADF Technology Stack

View

JSP

Controller

2-4

ADF UIX

Swing/
ADF JClient

Struts

ADF Model

Model

Business
Services

JSF

ADF
Business
Components

Web
Services

EJB
Session
Beans

Copyright 2004, Oracle. All rights reserved.

JavaBeans/
Others

A Sample Application

2-5

Is a two-page JSP or Struts application


Is based on the Order Entry schema delivered with
Oracle Database 10g

Copyright 2004, Oracle. All rights reserved.

Building an Application

1.
2.
3.
4.

Create an application workspace.


Select the technology scope.
Design the business services for the Model.
Design the application page flow for the
Controller.
5. Create pages for the View.

2-6

Copyright 2004, Oracle. All rights reserved.

Application Workspaces

An application workspace is a way of viewing the


components of your application.
JDeveloper provides several ways to view your
application:
Application-based view
File system view
Code-organized view

2-7

These views enable you to organize your project


the way that works best for you.

Copyright 2004, Oracle. All rights reserved.

Application Workspace Templates

JDeveloper provides application templates based


on technology choices.
You can create your own template, or you can
choose the technology template for your
application:
Web Application (default)ADF UIX, JSP, Struts,
and ADF Business Components
Web Application (JSP, Struts, and EJB)
Java Application (default)ADF JClient and ADF
Business Components
Java ApplicationJava, Swing/JFC, and JavaBeans
Custom ApplicationAll JDeveloper technologies

2-8

Copyright 2004, Oracle. All rights reserved.

Creating an Application Workspace

1. Click New Application


Workspace.
2. Enter a name.
3. Select the application
template.

2-9

Copyright 2004, Oracle. All rights reserved.

New Application Workspace

The application contains:


A project for the model (business services)
A project for the View and the Controller

2-10

Copyright 2004, Oracle. All rights reserved.

Design the Business Services for the


Model: ADF Business Components

2-11

Create ADF Business Components (Entity


Objects) from existing database tables.
Select the tables that you want to represent in the
Modelthese are the persistence components.

Copyright 2004, Oracle. All rights reserved.

Design the Business Services for the


Model: ADF Business Components

2-12

Business Components also


contain View components
(View objects).
View objects expose data to
client applications.
Select all the objects that you
want to expose to the client.
The wizard creates the objects
that you need.

Copyright 2004, Oracle. All rights reserved.

Design the Application Page Flow

2-13

JDeveloper uses Apache Struts as a Controller.


Apache Struts is an XML-driven page flow
controller.
JDeveloper provides a modeler to create and
manage Struts controller definitions.
Selecting Web Application Default as the
technology scope automatically generates a
default struts-config.xml file.
Tabs are provided in the editor to switch between
the visual modeler and the XML file.

Copyright 2004, Oracle. All rights reserved.

Create the Page Flow

To create a page flow, add a DataPage for each JSP


page in your application.

success
/customers

2-14

/orders

Copyright 2004, Oracle. All rights reserved.

Create JSP Pages

2-15

Double-click the DataPage to create a view


component.
Use a .jsp file name extension to create a JSP
page.
Use a .uix file name extension to create a UIX
page.
This opens the JSP or UIX Visual Editor.

Copyright 2004, Oracle. All rights reserved.

Using the Visual Editors

2-16

The Data Control Palette shows the data model


that you have defined.
Select the data elements that you want to display
on the page.
Use Drag and Drop As: to select how you want
to display the data.
Drag the element to the page.

Copyright 2004, Oracle. All rights reserved.

Databinding: Example

Display Customer as an input form:

2-17

Copyright 2004, Oracle. All rights reserved.

Adding HTML to Enhance the User


Interface
Add HTML to enhance the user interface.

2-18

Copyright 2004, Oracle. All rights reserved.

Results

Right-click the Customers DataPage, and select run.

2-19

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Build a simple default application by using
JDeveloper
Describe and use an application workspace
Create default ADF Business Components
Create a simple page flow diagram
Create and edit JSP Pages

2-20

Copyright 2004, Oracle. All rights reserved.

Practice 2-1: Overview

This practice covers the following topics:


Creating a JDBC connection
Opening an existing application
Testing the functionalities of the sample
application
Creating a new application workspace
Creating an application template

2-21

Copyright 2004, Oracle. All rights reserved.

Getting Started with ADF Business


Components

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Identify the two groups of Business Components
Define the purpose and function of Business
Components
Create an Entity Object
Create a View Object
Create an Application Module
Use the Business Components Browser to test an
application

3-2

Copyright 2004, Oracle. All rights reserved.

ADF Technology Stack

View

JSP

Controller

3-3

ADF UIX

Swing/
ADF JClient

Struts

ADF Model

Model

Business
Services

JSF

ADF
Business
Components

Web
Services

EJB
Session
Beans

Copyright 2004, Oracle. All rights reserved.

JavaBeans/
Other

What Are ADF Business Components?

3-4

ADF Business Components are part of ADF.


They provide business services for J2EE
applications.
They handle interaction between the client and the
data source of a J2EE application.
They provide validation services and business
logic to the J2EE application.
They provide application logic infrastructure code.

Copyright 2004, Oracle. All rights reserved.

ADF Business Components

Are a complete business tier


development framework
Implement J2EE design patterns
and best practice solutions for:
Business logic
implementation
Scalability and
performance
Optimized database
interaction

3-5

Support standard
deployment options: EJB,
Web tier, Web services
Copyright 2004, Oracle. All rights reserved.

Benefits of ADF Business Components

ADF Business Components increase productivity


Reusable components
Reentrant wizard-driven creation of objects
Simple O/R mapping

They provide application logic infrastructure


Ready-to-use data functions
No need to hand-code standard data access
routines.
You only code exceptions to standard behavior.

3-6

Copyright 2004, Oracle. All rights reserved.

Business Components

The Business Components framework comprises two


groups of components:
Business Domain components
Enforce business rules
Entity Objects, Entity Associations,
and Custom Object types

Data Model components


Provide data access to
client applications
View Objects, View Links,
and Application Modules

3-7

Copyright 2004, Oracle. All rights reserved.

Business Domain Components

Entity Objects
Enforce business rules and data validation
Persistence, caching
Data manipulation

Entity Associations
Enforce relational rules between entity objects

Custom Object Types (Domains)


Custom objects, such as AddressType
Object validation, such as EmailAddress

3-8

Copyright 2004, Oracle. All rights reserved.

Data Model Business Components

Application Modules
Manage transactions
Define data and methods that a client can see

View Objects
Provide client access to data
Are collections of data for client access

View Links
Link View Objects for Master-Detail coordination

3-9

Copyright 2004, Oracle. All rights reserved.

Business Components Model


Application
module
Application tasks
Transaction handling

OrderEntryApp
View
objects
PriorityOrder

ItemList

Entity
objects

Customers

3-10

Client-Facing
Reusable
Query
Components

Orders

OrderItems

Business Domain
Reusable
Business Logic
and Persistence
Components

Copyright 2004, Oracle. All rights reserved.

Building a Business Components Model

The basic steps to create a Business Components


model are:
1. Create a connection to a database.
2. Create an application workspace.
3. Create Entity objects based on database tables.
4. Create View objects to support a client
application.
5. Create an Application module to publish data
access methods.
6. Test the Business Components.

3-11

Copyright 2004, Oracle. All rights reserved.

Creating a Database Connection

A database connection provides access to database


object definitions and data.
To create a connection:
1. Select New Database Connection.
2. Complete the connection details:
Host name
Username and password
SID

3. Test the connection.

3-12

Copyright 2004, Oracle. All rights reserved.

Creating ADF Business Components:


Entity Objects

Entity objects encapsulate the business model:


Data
Rules
Persistence behavior

3-13

You can create one entity object for each of the


tables that you want to represent in your
application.

Copyright 2004, Oracle. All rights reserved.

Creating ADF Business Components:


Entity Objects
1. Select Business Components from Tables in the
New Objects Gallery.
2. Select a Database Connection.

3-14

Copyright 2004, Oracle. All rights reserved.

Creating ADF Business Components:


Entity Objects
Select the tables that you want to represent in your
application.

3-15

Copyright 2004, Oracle. All rights reserved.

Creating ADF Business Components: View


Objects

View objects expose data to client applications.


Create View objects that are specific to client
requirements by:

Selecting a specific attribute list


Creating nonpersistent attributes
Supplying a where clause
Supplying an order-by clause

Joining multiple entity objects

3-16

Views may have Links that manage Master-Detail


relationships between View objects.

Copyright 2004, Oracle. All rights reserved.

Creating ADF Business Components: View


Objects
Customer Name
Order Date
Order Status

Item Quantity
Item Price
Product Description

PriorityOrder

Customers

3-17

Orders

ItemList

OrderItems Products

Copyright 2004, Oracle. All rights reserved.

Creating Custom Views

1.
2.
3.
4.

3-18

Select New View Object from the New Gallery.


Name the View.
Select the entities to base the view on.
For a lookup usage, select the detail entity first.

Copyright 2004, Oracle. All rights reserved.

Selecting the Attributes

3-19

Select the attributes that you need from each of


the entities.
JDeveloper creates the View object with the SQL
Select statement.

Copyright 2004, Oracle. All rights reserved.

Creating an Application Module

3-20

The Application Module publishes View objects.


View objects must be part of the Application
Module for client applications to have access.
Edit the Application Module and add the Views.
Rename the View instancesuse names that
make sense for your client application.

Copyright 2004, Oracle. All rights reserved.

Testing the Business Components

3-21

Right-click the Application Module and select


Test.
Select the configuration and database connection.

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Describe the two groups of Business Components
Define the role of Business Components
Describe the role of an Application Module
Describe the use of customized Views

3-22

Copyright 2004, Oracle. All rights reserved.

Practice 3-1: Overview

This practice covers the following topics:


Creating Business Components:
Entity objects
View objects
Application Module

3-23

Testing an Application Module


Creating a Business Components diagram

Copyright 2004, Oracle. All rights reserved.

Building Business Logic

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to


do the following:
Decide where to place business logic
Describe entity objects role in business logic
implementation
Create entity objects
Describe the different methods of implementing
business logic in ADF Business Components
Add business logic to an ADF Business
Components application
Use the Business Components Modeler to create
and manage Business Components
4-2

Copyright 2004, Oracle. All rights reserved.

Business Logic Validation


Client tier

Middle tier

EIS tier

Web Container
ADF Business Services Tier
Model

Controller

Client
Validation
4-3

ADF
Application
Module

ADF
View
Object

ADF
Entity
Object

Business Logic
Validation
Copyright 2004, Oracle. All rights reserved.

Database

Database
Validation

Implementing Validation in the Business


Services Tier
Business logic tier:
Is used when creating or updating data
Assumes that existing data in the database is
valid
Is defined at entity object level
Uses programmatic or declarative techniques
Declarative: Defined in wizards and editors
Programmatic: Coded in Java

4-4

Is specified in Java or XML or both

Copyright 2004, Oracle. All rights reserved.

Entity Object: Overview


Entity
object

Customers
Id
Name
Status
Email

Attributes

Status List
(Gold Silver Platinum)

Validation
rule

CUSTOMERS
Database
table

4-5

ID

NAME

STATUS

201
202

Steve
Mike

Gold
Silver

Email
msmith@company.com
dgonzales@company.com

Copyright 2004, Oracle. All rights reserved.

Entity Object

Represents a database table or other data source


Handles all database interaction
Contains attributes representing the database
columns
Encapsulates attribute-level and entity-level
validation logic
Can contain custom business methods

Customer

4-6

Order

Copyright 2004, Oracle. All rights reserved.

Creating an Entity Object

4-7

Select the Business


Components node in
the New Gallery, and
then select Entity
Object.

Right-click the
package name in the
navigator, and select
New Entity Object.

Copyright 2004, Oracle. All rights reserved.

Entity Object Wizard

Enter
a name.
Select a
database
object.

Move to the
next step.

4-8

Copyright 2004, Oracle. All rights reserved.

Files Generated for the Customers


Entity Object

Customers.xml: Metadata
The Entity Object Wizard obtains all its information
from this file.
Is created by default (mandatory)

CustomersImpl.java: Entity object class


Extends the EntityImpl class
Is row level
Includes getter and setter methods for attributes
Is created by default (optional)

4-9

Copyright 2004, Oracle. All rights reserved.

Optional Files Generated for the


Customers Entity Object

CustomersDefImpl.java: Entity definition class


Extends the EntityDefImpl class
Contains run-time metadata describing the entity
object
Describes all instances of the entity

CustomersCollImpl.java: Entity collection


class
Extends the EntityCache class
Contains run-time querying the entity collection
Caches queried rows of the entity

4-10

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Modeler


for Entity Objects
1. Create a diagram from the New Gallery.
2. Drag objects to the diagram.
Entity objects
Database definitions

4-11

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Modeler


for Entity Objects

4-12

Create entity objects by using the Component


Palette.
Use the Entity Object Editor for Entity Object
properties.

Copyright 2004, Oracle. All rights reserved.

Assigning an Initial Value


to an Entity Attribute

Add code to the create() method in


EntityImpl.java.
Optional
Java files
selection
Select the Create
Method check
box to generate
a create()
method.

4-13

create() runs automatically when the entity is


instantiated.
Copyright 2004, Oracle. All rights reserved.

Mapping an Attribute to a
Database Sequence
create or replace trigger
insert_ord_id
BEFORE INSERT ON orders
FOR EACH ROW
DECLARE
new_id number;
BEGIN
SELECT orders_seq.NextVal
INTO new_id from Dual;
:new.order_id := new_id;
END;

1. Create a database
trigger.

2. Set the attribute type


to DBSequence.

4-14

Copyright 2004, Oracle. All rights reserved.

Practice 4-1: Overview

This practice covers the following topics:


Initializing an attribute to a default value
Assigning a database sequence to an attribute

4-15

Copyright 2004, Oracle. All rights reserved.

Adding Validation

Entity-level
validation

Attribute-level
validation

4-16

Copyright 2004, Oracle. All rights reserved.

Declarative Validation Rules

Use declarative validation rules to validate an


entity attribute.
Use the Entity Object Wizard to add and edit rules.
The Entity Object Wizard provides different types
of declarative rules:
Compare with a single value
Compare with a list of valid valueseither hard
coded or the results of a SQL query
Compare with the minimum value, maximum value,
or a range of values
Validate using a custom method

4-17

Declarative validation is XML based.


Copyright 2004, Oracle. All rights reserved.

ListValidator: Example

Specify a list of values for Customers.Status.

Customers.xml

4-18

Copyright 2004, Oracle. All rights reserved.

Adding UniqueKeyValidator to an Entity

A UniqueKeyValidator:

4-19

Implements validation in the middle tier


Checks uniqueness of the primary key for an
entity object
Checks that values are unique in the entity cache

Copyright 2004, Oracle. All rights reserved.

Domains

Use domains for more complex validation:

4-20

Format of a phone number


Validity of a URL
Validity of an e-mail address
Checksum of digits of a credit card number

Validation is done by the domain constructor.


A domain is not bound to a particular entity or
attribute.
You can use domains to validate multiple
attributes across multiple entity objects.

Copyright 2004, Oracle. All rights reserved.

Domains: Example

URLDomain verifies that an attribute is a valid URL.


The validate() method is called by the domains
constructor.
URLDomain.java
protected void validate()
{
try {
// Make sure the user entered a valid URL
java.net.URL u = new java.net.URL(mData);
}
catch (java.net.MalformedURLException e)
{throw new
oracle.jbo.domain.DomainValidationException
("Invalid URL");
}

4-21

Copyright 2004, Oracle. All rights reserved.

How to Create a Domain

1. Create the domain from the New Gallery.


2. Add validation code to the validate() method
automatically created in URLDomain.java.

4-22

Copyright 2004, Oracle. All rights reserved.

How to Use a Domain

Edit the entity object and change the type of an


attribute to URLDomain.

URLDomain
appears in the
list of types.

4-23

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Implement declarative business logic
Create entity objects
Generate Java code for entity objects
Validate entity attributes using validation rules or
domain objects
Use the Business Component modeler

4-24

Copyright 2004, Oracle. All rights reserved.

Practice 4-2: Overview

This practice covers the following topics:


Adding a list validator to an attribute
Creating a domain
Assigning an attribute to a domain

4-25

Copyright 2004, Oracle. All rights reserved.

Exposing Business Data

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to


do the following:
Describe the role of view objects in the business
components framework
Create view objects
Customize view objects by using the View Object
Wizard
Define relationships between view objects
Add calculated attributes to view objects
Explain the role of an application module
Create an application module

5-2

Copyright 2004, Oracle. All rights reserved.

View Object in the ADF Architecture


Client Tier

Middle Tier

EIS Tier

Web Container
ADF Business Services Tier
Model

Controller

5-3

ADF
Application
Module

ADF
View
Object

ADF
Entity
Object

Copyright 2004, Oracle. All rights reserved.

Database

Overview
View object

Entity object
Customers

CustomerStatus
SELECT name, status
FROM customers
ORDER BY name
Name

ID
Name
Status
Web site

5-4

Mike
Steve
Susan

ID

NAME

STATUS

WEBSITE

201
202

Steve
Mike

Gold
Silver

http://www...
http://www...

Database
table

Copyright 2004, Oracle. All rights reserved.

Status
Silver
Gold
Platinum

View Objects

Present a view or slice of business data


Are used for joining, filtering, projecting, and
sorting your business data
Can be based on any number of entity objects
Can also be constructed from a SQL statement

PriorityOrder

Order

5-5

CustomerStatus

Customers

Copyright 2004, Oracle. All rights reserved.

Interaction Between Views and


Entities: Retrieving Data

The view object queries the database directly.


Data retrieved by the query is saved to the entity
objects cache.
EO

getAttr()

VO

Nonpersistent attributes are stored and retrieved


from the view object's cache.

getCalcAttr() VO
5-6

Copyright 2004, Oracle. All rights reserved.

Interaction Between Views and


Entities: Updating Data

The view object updates the entity objects cache.


The entity object updates the database.

setAttr()

EO

5-7

Copyright 2004, Oracle. All rights reserved.

VO

Synchronization of View Objects

When an application module is run, multiple views that


reference the same entity stay synchronized.

Order status
is changed in
one view.
New value is immediately
displayed in other views
based on same entity.
5-8

Copyright 2004, Oracle. All rights reserved.

Creating a View Object


Using the View Object Wizard

5-9

Copyright 2004, Oracle. All rights reserved.

Classes Related to View Objects

ViewObjectImpl
This is the view object class.
It represents a view object.
Use this class to add or override behaviors that
apply to the view object.

ViewRowImpl
This is the view row class.
It represents a row in a view object.
Use this class to add or override behaviors that
apply to a row within the view object.

5-10

Copyright 2004, Oracle. All rights reserved.

Files Generated for the LineItemView


View Object

LineItemView.xml: Metadata
It is always generated.
The ADF framework retrieves
run-time metadata from this file.
JDeveloper design time uses this
file for View Object properties.

LineItemViewImpl.java: The view class


It extends ViewObjectImpl.
Its generation is optional.

LineItemViewRowImpl.java: The view row class


Extends ViewRowImpl
Generation is optional.

5-11

Copyright 2004, Oracle. All rights reserved.

Example of a View Object


PriorityOrder View Object
SELECT Cust.ID, Cust.FIRSTNAME,
Cust.LASTNAME, Cust.STATUS
Ord.ID, Ord.ORDERDATE,
Ord.STATUS
FROM CUSTOMERS Cust, ORDERS Ord
WHERE Cust.ID = Ord.CUSTOMER_ID
AND Cust.status = 'Platinum'
ORDER BY Ord.ORDERDATE

5-12

Customers

Orders

ID
FirstName
LastName
Status
Email

ID
Orderdate
Status
Custid
Trackingno

Copyright 2004, Oracle. All rights reserved.

Practice 5-1: Overview

This practice covers creating and editing a new


view object.
Select entity
objects
Select
attributes
Edit the
query

5-13

Copyright 2004, Oracle. All rights reserved.

Calculated Attributes in Views

5-14

You can add nonpersistent (transient) attributes


based on calculated fields and function calls.
Click New on the Attributes tabbed page of the
View Object Editor.

Copyright 2004, Oracle. All rights reserved.

View Links

A view link is an active link between view objects.


You can create view links by providing the
following:
Source and destination views
Source and destination attributes

5-15

InventoryItem

OrderForItem

LineItem

Source
view object

Link

Destination
view object

Copyright 2004, Oracle. All rights reserved.

Traversing Links

Links may be traversed in either direction.


ViewRowImpl.java contains a method to get the
associated row iterator.
Use the methods of RowIterator to move from
row to row and get individual attribute values.
For example, OrdersViewRowImpl contains the
method:
public oracle.jbo.RowIterator getOrderItemsView()

5-16

This method returns the detail items for an order.

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Modeler


for View Objects (I)

Drag view objects from the Applications Navigator


to the diagram.
Source entity object appears in the view object
box.

Source
entity
object

5-17

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Modeler


for View Objects (II)
1. Create an empty view object from the Component
Palette.
2. Drag entity objects to the view box.

5-18

Copyright 2004, Oracle. All rights reserved.

Application Module in the ADF


Architecture
Client Tier

Middle Tier

EIS Tier

Web Container
ADF Business Services Tier
Model

Controller

5-19

ADF
Application
Module

ADF
View
Object

ADF
Entity
Object

Copyright 2004, Oracle. All rights reserved.

Database

Application Modules

5-20

Represent the data model for clients


Track all changes that affect the database
Have one connection to the database
Provide remotely accessible methods
May be deployed to multiple platforms without
code changes
May contain other application modules

Copyright 2004, Oracle. All rights reserved.

Creating an Application Module Using the


Application Module Wizard

5-21

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Modeler


for an Application Module (I)

5-22

Drag an application module from the Applications


Navigator to the diagram.
Source view objects appear in the Application
Module box.

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Modeler


for an Application Module (II)
1. Create an empty application module from the
Component Palette.
2. Drag view objects to the Application Module box.

5-23

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Describe the role of view objects in the business
components framework
Create view objects
Customize view objects using the View Object
Wizard
Define relationships between view objects
Add calculated attributes to view objects
Explain the role of an application module
Create an application module

5-24

Copyright 2004, Oracle. All rights reserved.

Practice 5-2: Overview

This practice covers the following topics:


Adding a calculated attribute to a view object
Modifying the source code to recalculate the
attribute when the view row changes

5-25

Copyright 2004, Oracle. All rights reserved.

Adding Custom Validation

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Add custom methods to validate business data
Use the typesafe data access methods
Use entity associations in business logic
Traverse entity associations

6-2

Copyright 2004, Oracle. All rights reserved.

Overview

Entity Object

Validation Type

Customers
Id
Name
Status
Email

Attribute
Method Validator

6-3

Name must not


be longer than
50 characters

Domain

E-mail must
contain an "@"
and "."

Entity
Method
Validator

Customer e-mail
must exist
If the OrderMode
is "ONLINE"

Orders
Id
CustomerId
OrderMode
OrderTotal

Business Rule

Copyright 2004, Oracle. All rights reserved.

Adding Validation to an Entity

There are a number of places you can put validation:


Predefined validators: For simple XML-based rules
Custom method validators: For more complex
attribute and entity rules
Attribute setter method: For complex attribute
rules
Override EntityImpl.java methods: For more
complex entity rules and custom behaviors
Domains: Can be used for multiple attributes
across multiple entity objects

6-4

Copyright 2004, Oracle. All rights reserved.

Validating Attributes

To create custom validation for attributes, you can


either:
Create a MethodValidator in the
EntityImpl.java file
or
Modify the setter() method of the attribute in
the EntityImpl.java file

6-5

Copyright 2004, Oracle. All rights reserved.

Creating a MethodValidator for an


Attribute
To create a custom validator, create a new method in
the EntityImpl.java file. Select the
EntityImpl.java file in the Structure pane or select
Go to Entity Object Class from the context menu.

6-6

Copyright 2004, Oracle. All rights reserved.

Creating a MethodValidator for an


Attribute
To create the custom validation as a
MethodValidator, the method must:

Be defined as public
Accept a single argument of the same type as the
attribute
Return a Boolean value
Start with validate

public boolean validateEmail(String value)


{
return (value.indexOf('@') != -1 );
}

6-7

Copyright 2004, Oracle. All rights reserved.

Utilizing Typesafe Methods

EntityImpl.java contains typesafe methods to get


and set each of the entitys attributes.
To override the setter method in the
EntityImpl.java file:

Add custom validation code in the methods.


Call setAttributeInternal() to set the
attribute value after your validation code.
public void setCreditLimit(Number value)
{
// add your custom code here
setAttributeInternal(CREDITLIMIT, value);
}

6-8

Copyright 2004, Oracle. All rights reserved.

Validating Entity Objects

MethodValidators can also be created in the


EntityImpl.java file to validate entity objects.
Custom entity validation methods must:
Be defined as public
Return a Boolean value
public boolean validateOrder()
{ String date = new java.util.Date().toString();
if( (getOrderStatus().equals("2")) &&
(getOrderDate().toString() == date ))
{return true;

else {return false;}}


6-9

Copyright 2004, Oracle. All rights reserved.

Validating Entity Objects

If entity MethodValidators are too limiting, create a


custom method in the EntityImpl.java file:
public boolean checkOrderMode(){
if ( ("ONLINE".equals(getOrderMode())) ||
!(getCustomerEmail() == null))
{ //success
}
else {
// Error - online order must have email address
}}

6-10

Copyright 2004, Oracle. All rights reserved.

Call EntityImpl Methods

You can also override other methods in


EntityImpl.java. For example:
doDML()Log changes in another entity
beforeCommit()Validate multiple instances of
the same entity
remove()Record a deletion in another entity

6-11

Copyright 2004, Oracle. All rights reserved.

Validation Order

Attribute validation occurs in the following order:


Domain validation: On instantiation of an entity
object
Setter method: On creation or modification of
an attribute
Predefined validators: On a call to
setAttributeInternal()
Attribute MethodValidators
validateEntity() method
Entity MethodValidators
doDML() method
beforeCommit() method
6-12

Copyright 2004, Oracle. All rights reserved.

Associations

Associations define a relationship between entity


objects. Associations:
Facilitate access to data in related entity objects
May be based on database constraints
May be independent of database constraints
Consist of a source (master) and a destination
(detail) entity

6-13

Copyright 2004, Oracle. All rights reserved.

Association Example

A customer can place one or many orders.


An order is placed by just one customer.

Customers
Source

6-14

OrderPlacedBy
Association

Copyright 2004, Oracle. All rights reserved.

Orders
Destination

Accessor Methods

Are optional methods created by the Association


Wizard
Provide access to data from the associated entity
Are bidirectional
For example:
Get all orders for a customer
Get customer information from an order

6-15

Copyright 2004, Oracle. All rights reserved.

Association Types

Association
Entities are related but not completely dependent.
Either end of the association can exist without the
other.
It is usually a categorization.

Composition
Destination entity is completely dependent on the
source entity.
The source entity owns the destination entity.
No destination entity can be created without the
owning entity existing first.

6-16

Copyright 2004, Oracle. All rights reserved.

Determining the Association Type

Two questions to ask:


Can a destination entity object exist without the
source?
If yes, the source is associated to the destination.
If no, the source is composed of the destination.

When I delete the source, do I delete the


destination?
If yes, the relationship is a composition.
If no, the relationship is an association.

6-17

Copyright 2004, Oracle. All rights reserved.

Creating Entity Associations

The one
side of the
association

6-18

The many
side of the
association

Copyright 2004, Oracle. All rights reserved.

Creating Entity Associations

6-19

Copyright 2004, Oracle. All rights reserved.

Traversing Associations:
Destination to Source
LineItem

Order
getLineItem()

ItemOrderedOnAssoc

getTrackingNo()

The destination entitys EntityImpl.java file


contains methods to get and set the source entity.
For example, LineItemImpl.java contains
getOrd() and setOrd().
You can add a method to LineItemImpl.java to
get the tracking number of the order containing
this item:
public String getTrackingNo() {
return getOrd().getTrackingNo(); }

6-20

Copyright 2004, Oracle. All rights reserved.

Traversing Associations:
Source to Destination
LineItem

Order
getLineItem()

ItemOrderedOnAssoc

The source entitys EntityImpl.java file


contains a method to get the destination entity.
For example, OrdImpl.java contains the method:
public oracle.jbo.RowIterator getLineItem()

6-21

Use the methods of RowIterator to step from


row to row and get individual attribute values.

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Add business rules to ADF Business Components
Validate entities, attributes, and domains
Test the validation rules

6-22

Copyright 2004, Oracle. All rights reserved.

Practice 6-1: Overview

This practice covers the following topics:


Enforcing ListValidator rules

6-23

Creating domain validation code


Testing the validation rules

Copyright 2004, Oracle. All rights reserved.

Providing for Efficient Queries

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Create view objects in expert mode
Use parameterized queries in view objects
Implement custom methods
Create a Java program to test custom methods

7-2

Copyright 2004, Oracle. All rights reserved.

Overview

View object
CustomerOrders
Customers
ID
Name
Status
Email

select c.name,
o.order_total from
customers c,
orders o where
c.id=o.customer_id

Orders
ID
CustomerId
OrderMode
OrderTotal
7-3

Custom method
getFullName()

Copyright 2004, Oracle. All rights reserved.

Expert Mode View Objects

Use expert mode queries to create custom view


objects. Select expert mode in the Create View Object
Wizard or in the Query category of the View Object
Editor.

7-4

Copyright 2004, Oracle. All rights reserved.

Mapping Attributes in Expert Mode

In normal mode, JDeveloper maintains mappings


between entity attributes and database columns.
Editing a query in expert mode may invalidate
these mappings.
For example, edit the CustomersView query:
SELECT ID, NAME, initcap(STATUS) AS Status
FROM CUSTOMERS

7-5

At run time, the value of the Status attribute does


not match the value in the underlying table.
Performing an update with the view gives a
locking error.

Copyright 2004, Oracle. All rights reserved.

Maintaining Attribute Mappings


in Expert Mode

You are responsible for maintaining the correct


mapping between entity attributes and database
columns.
For the customer status example:
Delete the Status attribute from your view object.
Create a new calculated attribute called Status.

7-6

Copyright 2004, Oracle. All rights reserved.

SQL-Based View Objects

A SQL-based view object:


Is not based on any entity object
Cannot be used for insert, update, or delete

Use SQL-based view objects for query-only


views, which do not need the functionality of
entity objects.
SQL-based view objects provide better
performance than entity-based view objects.

SELECT...

7-7

VO

Copyright 2004, Oracle. All rights reserved.

Creating a SQL-Based View Object

7-8

Create a view object without selecting an entity


object in the View Object Wizard.
Click the Query tab of the wizard, and enter your
query in the field provided.

Copyright 2004, Oracle. All rights reserved.

Implementing Custom Methods

To add custom methods to a view object, modify the


ViewObjectRowImpl.java file:
public String getCustFullName()
{
String custFullName = "";
custFullName = getCustFirstName() +
" " + getCustLastName();
return custFullName;
}

7-9

Copyright 2004, Oracle. All rights reserved.

Expose Methods to the Client Application

Expose the view object client row methods:


getCustFirstName(), getCustLastName()
getCustFullName()

7-10

Copyright 2004, Oracle. All rights reserved.

Creating a Test Client

To create a test client:


1. Instantiate the application module.
2. Instantiate the view object.
3. Find and manipulate data as required.
4. Call custom methods as required.
5. Close the application module.

7-11

Copyright 2004, Oracle. All rights reserved.

Instantiating an Application Module

Instantiate the application module by using the


Configuration class.
Use the fully qualified application name and the
configuration name as arguments.
String _am
String _cf

// App module name


= "model.OEModule";
// Configuration name
= "OEModuleLocal";

// Create an instance of the AppModule


ApplicationModule am =
Configuration.createRootApplicationModule(_am,_cf);

7-12

Copyright 2004, Oracle. All rights reserved.

Instantiate a View Object and Output Data

Use findViewObject() to instantiate the view


object.
Iterate through the Rowset.
Display the data by using getAttribute().

ViewObject vo = am.findViewObject("CustomersView");
while (vo.hasNext()) {
CustomersViewRow row = (CustomersViewRow) vo.next();
System.out.println("Customer First Name is " +
row.getAttribute("CustLastName));
}
Configuration.releaseRootApplicationModule(am,true);
7-13

Copyright 2004, Oracle. All rights reserved.

Calling Custom Methods

1. Retrieve the View Object Row.


2. Call the published methods on the view object.

System.out.println("Customer First Name: " +


row_Cust.getCustFirstName());
System.out.println("Customer Last Name: " +
row_Cust.getCustLastName());
System.out.println("Customer Full Name: " +
row_Cust.getCustFullName());

7-14

Copyright 2004, Oracle. All rights reserved.

Setting Parameters for the Where Clause

The Where clause of a view objects query can contain


either variables or parameters.
Provides flexibility at run time
Can be JDBC style
customer_id = ?

Can be Oracle style


customer_id = :1

7-15

Copyright 2004, Oracle. All rights reserved.

Setting Parameters for the Where Clause

At run time, you can assign values to the parameters.

Parameters

7-16

Copyright 2004, Oracle. All rights reserved.

Assigning Values to Queries with


Parameters at Run Time
1. Assign parameters within the client.
2. After assigning parameters, reexecute the query.
ViewObject vo = am.findViewObject("CustParamView");
vo.setWhereClauseParam(0, "S");
vo.setWhereClauseParam(1,
new oracle.jbo.domain.Number(10));
vo.executeQuery();

7-17

Copyright 2004, Oracle. All rights reserved.

Creating a View Object at Run time

To create a new view object based on an entity:


//am is an ApplicationModule
String entity = "orders.LineItem";
String selectClause = "id, status, quantity";
String fromClause = "line_item";
String whereClause = "status = 'S'";
ViewObject shippedItemsVo =
am.createViewObjectFromQueryClauses(null, entity,
selectClause, fromClause, whereClause, null);

To create a new view object based on a query:


ViewObject queryItemsVo =
am.createViewObjectFromQueryStmt("",
"select id, status, quantity from line_item");

7-18

Copyright 2004, Oracle. All rights reserved.

Finding Data by a Row Key

Check the command-line argument.


Create an oracle.jbo.Key object.
Call findByKey(), which returns an array of
row objects.
if (args.length==0) {
system.out.println("Customer ID is required");
System.exit(0);
}
Key custKey = new Key(new Object[] {args[0]});
Row[] customers = vo.findByKey(custKey,1);

7-19

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Create expert mode and programmatic view
objects
Customize ADF Business Components to include
custom methods
Use parameterized queries in view objects
Test custom methods by using a command-line
Java client

7-20

Copyright 2004, Oracle. All rights reserved.

Practice 7-1: Overview

This practice covers the following topics:


Creating a programmatic view object
Creating parameterized queries
Creating custom methods for a view object
Testing custom methods and providing query
parameters by using a command-line Java client

7-21

Copyright 2004, Oracle. All rights reserved.

Making the Model Secure

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Define Java Authentication and Authorization
Services (JAAS)
Define security issues with respect to Web
applications
Use ADF Model Security design-time features
Use the ADF Business Components Browser to
test your security model

8-2

Copyright 2004, Oracle. All rights reserved.

Goals of J2EE Security Architecture

8-3

To decouple security logic from application logic


To maintain platform and vendor independence
To ensure fine-grained access control to
resources
To enable portable and secure Web applications

Copyright 2004, Oracle. All rights reserved.

Overview of J2EE Security Architecture

Use JAAS APIs to:


Authenticate a client to access
the system
Determine who the user is.
Can they prove it?

Authentication

Authorize clients to access


resources
Determine the role of the
authenticated user.
What actions can a user
perform?

8-4

User

Copyright 2004, Oracle. All rights reserved.

Authorization

Read/Write
Application

Java Authentication and Authorization


Services

JAAS is a framework that:


Provides a Java API package to enable applications
to authenticate and enforce security
Allows definition of logical security names
(principals) that are mapped to users or roles
defined in the run-time environment
Allows fine-grained authorization to manage how
clients can access resources

8-5

A JAAS provider implements the JAAS framework


and applies the Java2 Security Model.

Copyright 2004, Oracle. All rights reserved.

Java Authentication and Authorization


Services

JAAS supports the following authorization,


authentication, and user community (realm)
features:

8-6

Principals
Subjects
Login module authentication
Roles
Realms
Policies and permissions

JDeveloper provides wizards and dialogs that help


manage these objects.

Copyright 2004, Oracle. All rights reserved.

JDeveloper, JAAS, and Securing the ADF


Model

8-7

JDeveloper provides application security by using


JAAS.
ADF Business Components use the JAAS security
definitions to enforce security in the model.
You can set access roles on entities and
attributes.
The ADF Business Component Browser uses this
property to control model security during
development and testing.
JDeveloper deployment uses these access roles
to build deployment descriptors.

Copyright 2004, Oracle. All rights reserved.

Enabling JAAS Authentication for ADF


Business Components

Set the jbo.security.enforce application


property to enable authentication and
authorization.
Select
None: No authentication
Test: Will test the login scheme but will not
authenticate users
Must: Full authentication
Auth: Full authentication and authorization

8-8

Modify java.security to use the Oracle login


provider.

Copyright 2004, Oracle. All rights reserved.

The jbo.security.enforce Application


Property
1. Select the Application Module Configuration
Editor.
2. Click the Properties tab.
3. Set the jbo.security.enforce property.

8-9

Copyright 2004, Oracle. All rights reserved.

Setting Entity Permissions

8-10

Copyright 2004, Oracle. All rights reserved.

Entity Privileges

8-11

The users role can


update new rows.
The administrators
role can update any
rows.
The guests role can
only read any row.

Copyright 2004, Oracle. All rights reserved.

Attribute Permissions

Attributes inherit entity permissions.


Permissions can be overridden at the attribute
level.
The most restrictive permissions applyfor
example:
If you set read-only at the entity level, you cannot
set update at the attribute level.
Update at the entity level can have read-only at the
attribute level.

8-12

Copyright 2004, Oracle. All rights reserved.

Using the Business Components Browser

8-13

Choose Test from the Application Module context


menu.
Choose AppModuleLocal for the testing
configuration.

Copyright 2004, Oracle. All rights reserved.

Testing Entity and Attribute Authorization

8-14

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Set the login configurator for ADF BC applications
Enable JAAS authentication for ADF BC
Add users and roles
Add role-specific permissions to entities and
attributes
Test an ADF BC application security scheme

8-15

Copyright 2004, Oracle. All rights reserved.

Practice 8-1: Overview

This practice covers the following topics:


Setting up SSO authentication
Creating users and roles
Adding authorizations
Testing the authorizations

8-16

Copyright 2004, Oracle. All rights reserved.

Controlling an Application with Struts

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Define the role of the controller in the MVC
architecture
Define page navigation in a Struts application
Handle success and exception navigation
Define the different ways of editing Struts
configuration

9-2

Copyright 2004, Oracle. All rights reserved.

The Controller
Client Tier

Middle Tier

EIS Tier

Web Container
ADF Business Services Tier
Model

Controller

9-3

ADF
Application
Module

ADF
View
Object

ADF
Entity
Object

Copyright 2004, Oracle. All rights reserved.

Database

ADF Implements MVC Using the Struts


Controller
View

JSP

Controller

9-4

ADF UIX

Swing/
ADF JClient

Struts

ADF Model

Model

Business
Services

JSF

ADF
Business
Components

Web
Services

EJB
Session
Beans

Copyright 2004, Oracle. All rights reserved.

JavaBeans/
Other

Purpose of a Controller

On a Web page, everything significant happens on


submit or a link.
A controller intercepts a request and dispatches it
correctly.
The source page does not have to know how to
handle an event or where to go next.
The handling code does not need to know what
page to display in response.
The controller separates the model and the view.

9-5

Copyright 2004, Oracle. All rights reserved.

Example: Page Flow Without a Controller

<a href="page2.jsp">
<a href="page1.jsp">
page1.jsp

9-6

page2.jsp

Copyright 2004, Oracle. All rights reserved.

Example: Page Flow Without a Controller

<a href="page2.jsp">
<a href="page1.jsp">
page1.jsp

page2.jsp

page1a.jsp
9-7

Copyright 2004, Oracle. All rights reserved.

Example: Page Flow Without a Controller

<a href="page2.jsp">
<a href="page1.jsp">
page1.jsp

page2.jsp

page1a.jsp
9-8

Copyright 2004, Oracle. All rights reserved.

Example: Page Flow Without a Controller

page1.jsp

page2.jsp

<a href="page1a.jsp">

<a href="page1a.jsp">

page1a.jsp
9-9

Copyright 2004, Oracle. All rights reserved.

Example: Page Flow with a Controller

Controller
Next

page1.jsp

9-10

Previous

page2.jsp

Copyright 2004, Oracle. All rights reserved.

Example: Page Flow with a Controller


Controller
Previous

Next

Next

Previous

page1.jsp

page2.jsp

page1a.jsp
9-11

Copyright 2004, Oracle. All rights reserved.

What Is Struts?

Project from the Apache Software Foundation


http://jakarta.apache.org/struts
Open source framework for MVC Web-based
applications
XML-driven controller servlet

De facto standard for JSP Model 2 development


Partially declarative, partially coded
Often used with other view layers
Tiles: A page layout mechanism using JSP
templates
Velocity: Page scripting language

9-12

Copyright 2004, Oracle. All rights reserved.

Struts Components
View

Tags

JSP

Action Form

Controller Servlet

Action

Resource Bundle

Controller

Struts Config

Model
Model

9-13

Copyright 2004, Oracle. All rights reserved.

Struts Components

9-14

Struts Controller Servlet: Handles requests and


marshals results
Struts configuration file: The roadmap for the
servlet
Actions: Processes a request and sends an action
forward
ActionForms: Passes information between the
client and the model
TagLibs: Set of Struts library tags usable in JSPs
Resource bundles: Text-based file used for
internationalization of messages

Copyright 2004, Oracle. All rights reserved.

Struts Components Flow


HTTP Request

Struts
Controller Servlet

Action

Model

Action
Form
validate()

Forward
execute()

9-15

Copyright 2004, Oracle. All rights reserved.

Return
Response
Page

Struts Components:
The Controller Servlet

9-16

Controls the overall application process


Does not appear in the Applications Navigator
pane of JDeveloper
Is referenced in the web.xml file

Is designed to be extended
Is driven by XML

Copyright 2004, Oracle. All rights reserved.

Struts Components:
The Configuration file

Is named struts-config.xml

Is used by the controller servlet


Provides the metadata that defines the
application:

9-17

Action mappings (abstractions)


Page flow
Data flow
Exception handling
Resources

Copyright 2004, Oracle. All rights reserved.

Struts Components:
Actions

Actions process requests, via its


execute() method, and return ActionForward
objects that identify where control should be
forwarded.
Actions are adapters between HTTP requests and
the corresponding business logic .
The possible tasks that can be specified for an
action are:

9-18

Forward to/represent a page


Encode page flow logic
Take data from the page and update the model

Copyright 2004, Oracle. All rights reserved.

Struts Components:
ActionForms (Form Beans)

Represent HTML form data that the user


enters
Shuttle data between the view and the action:
Fields in the page are populated from the
ActionForm.
On submit, the ActionForm is repopulated from
the page.
Populated ActionForm is passed to the handling
action for processing.

9-19

Copyright 2004, Oracle. All rights reserved.

Struts Components:
Tag Libraries

9-20

Tag libraries integrate the JSP and controller


components
<html:form/> Directs the controller to the
correct action on submit
<html:errors/> Displays any errors thrown by
the model, including validation
<bean:message/> Outputs a string from the
resource file (a field label, for example)
Much overlap with newer tag libraries, for
example JSTL

Copyright 2004, Oracle. All rights reserved.

Application Resources File

Centralizes all messages for the


application, making message maintenance
and internationalization easy to perform
Has default name
ApplicationResources.properties
Associates a key name to a value
link.logonpage = Click here to Login

Is used with the Struts tags and error routines


<html:link page="/logonPage.do">
<bean:message key="link.logonPage"/>
</html:link>

9-21

Copyright 2004, Oracle. All rights reserved.

Internationalizing Your Application

To internationalize an application, perform


these steps:
Create other bundle files.
Add the country code to the file name such as
ApplicationResources_fr.properties.

Translate the message text:


logon.title=Entrez votre nom dutilisateur

9-22

The servlet then checks the browser locale


variable at startup, and the corresponding file is
loaded if found; otherwise the default file is
loaded.

Copyright 2004, Oracle. All rights reserved.

Struts in
Oracle JDeveloper 10g

JDeveloper supports Struts 1.1.


You can visualize the page flow from the modeler
and:
Drill down to JSP/UIX Visual Editor for pages
Drill down to Code Editor for actions

You can edit in whatever way you choose:


Visually
Through the Structure pane and Property Inspector
In the XML

9-23

Copyright 2004, Oracle. All rights reserved.

Struts Configuration File

It is written in XML.
It is the road map of the application.
It can be cumbersome to update directly.
JDeveloper provides a graphical editing tool,
free of XML syntax.

<struts-config>
<action-mappings>
<action path="/action1">
<forward name="success" path="/page1.do"/>
</action>
</action-mappings>
<message-resources
parameter="view.ApplicationResources"/>
</struts-config>

9-24

Copyright 2004, Oracle. All rights reserved.

Defining the struts-config.xml


File Content
The Structure pane and Property Inspector
<struts-config>
<action-mappings>
<action path="/action1" type="view.Action1Action">
<forward name="success" path="/page1.do"/>
</action>
<action path="/page1" forward="/page1.jsp"/>
</action-mappings>
<message-resources
parameter="view.ApplicationResources"/>
</struts-config>

9-25

Copyright 2004, Oracle. All rights reserved.

Defining the struts-config.xml


File Content
Using the Struts Configuration Editor
<struts-config>
<action-mappings>
<action path="/action1" type="view.Action1Action">
<forward name="success" path="/page1.do"/>
</action>
<action path="/page1" forward="/page1.jsp"/>
</action-mappings>
<message-resources
parameter="view.ApplicationResources"/>
</struts-config>

9-26

Copyright 2004, Oracle. All rights reserved.

Defining the struts-config.xml


File Content
The Struts Page Flow Diagram and
Component Palette
<struts-config>
<action-mappings>
<action path="/logon" type="view.LogonAction">
<forward name="success" path="/customers.do"/>
</action>
<action path="/customers" forward="/customers.jsp"/>
<action path="/orders" forward="/orders.jsp"/>
</action-mappings>
<message-resources
parameter="view.ApplicationResources"/>
</struts-config>

9-27

Copyright 2004, Oracle. All rights reserved.

Creating a Page Flow Diagram

9-28

Using the Component Palette, drag


components to the diagram.
Components do not exist until you physically
create them (either as a Java class or a JSP).

Copyright 2004, Oracle. All rights reserved.

Struts Components:
Actions
To create an action:
Use the Action icon to draw actions and
ActionForms on the Page Flow Diagram
Specify the path name for the action
The path name is a logical name
Modify the execute() method
Return a forward

9-29

Copyright 2004, Oracle. All rights reserved.

Struts Components:
Pages and Page Forwards

Pages symbolize the users view.


Creating a page forward
(also called ActionForward):
Creates an action entry in the struts-config.xml
file
Creates a logical name associated with the page
name

Creating a page
Makes a direct reference to the page name
Requires to be changed for every occurrence
of the page when renaming it

9-30

Pages need to physically exist to be used as the


target of a forward or link
Copyright 2004, Oracle. All rights reserved.

Struts Components:
Forwards and Links

A link represents a flow between components


You can create a link (unnamed dotted line):
Between pages
Between a page and an action

You can create a forward (named line):


Between actions
Between an action and a page
Default name of the first forward is Success.

9-31

More than one forward or link may exist at the


source of a component.

Copyright 2004, Oracle. All rights reserved.

ADF Components: DataAction and


DataPage
ADF provides two specialized action-subclassed
components:
DataPage
Create for databound pages
Used extensively in default ADF business
component applications
Combination of a DataAction and a
standard Struts Page Forward

DataAction
Create as a standalone action for executing
custom methods of the business service
Handles standard actions from databound pages

9-32

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned the following


about Struts applications:
The Struts controller servlet intercepts each
request.
The struts-config.xml file defines
components:
Actions (Processes a request)
Action Forwards (Pass HTML form data)
Page Forwards and/or Pages (Symbolize the users
view of an action's result)
Resource Bundles (Componentization of Labels and
Text)
Navigation (Forwards and Page Links)
9-33

Copyright 2004, Oracle. All rights reserved.

Practice 9-1: Overview

This practice covers the following topics:


Creating a Page Flow Diagram
Creating a page forward for each screen
Associating each of the JSP screens to a specific
page forward action.
Adding a DataAction between the logon and
customer screens.
Linking the DataAction to the logon screen

9-34

Copyright 2004, Oracle. All rights reserved.

Building ADF View Components

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Describe how a JSP works
Describe the fundamental components of a JSP
Create a JSP
Include components into JSP (HTML, Struts, and
JSTL tags)
Create a data-centric JSP using ADF data binding

10-2

Copyright 2004, Oracle. All rights reserved.

What Is a JSP?

JavaServer Pages are a


J2EE component, which:
Is a View in the ADF
MVC structure
Contains presentation
logic
Mixes HTML, Java, and XML in a page
Enables Web developers to create applications
that focus on the look and feel of an application
Is based on the servlet architecture
Supports the use of custom tags and beans to
incorporate presentation logic
10-3

Copyright 2004, Oracle. All rights reserved.

JavaServer Pages in ADF

Calls

Request

Client

JSP

Struts

Generates
Controls

Dynamic content
Response
10-4

Copyright 2004, Oracle. All rights reserved.

ADF Business
Components

Example: JSP

<%@ page contentType="text/html;charset=WINDOWS-1252"%>


<html> <head>
<title> Show Date </title>
</head>
<body>
<h2> The current time is: </h2>
<p> <%= new java.util.Date() %> </p>
</body>
</html>

10-5

Copyright 2004, Oracle. All rights reserved.

Basic JSP Elements

A JSP can contain HTML text and four main elements:


Element

10-6

Syntax

Purpose

Scriptlets

<% if(x == null) { %>


Hello! <% } %>

Java code

Expressions

<%= "a" + "b" %>

Java code
that is
evaluated

Directives

<%@ page
language="java" %>

Global values

Declarations

<%! private int


hitCount = 0; %>

Variable
declarations

Copyright 2004, Oracle. All rights reserved.

JSP Directives

There are three types of JSP directives:


page
include
taglib
<%@ page contentType="text/html;charset=WINDOWS1252"%>
<%@ include file="signature.html" %>

<%@ taglib uri="webapp/taglib.tld"


prefix="mytags" %>
<html> <body>
<h2> The current time is: </h2>
<p> <%= new java.util.Date() %> </p>
</body>
</html>
10-7

Copyright 2004, Oracle. All rights reserved.

JDeveloper and JSPs

JDeveloper contains several IDE features to simplify


JSP development:
Visual Editor (WYSIWYG)
Component Palette
Many Custom Tag libraries are included,
including:

10-8

JSP Standard Tag Library (JSTL)


Apache Struts
Oracle JSP
ADF Data Tags

Copyright 2004, Oracle. All rights reserved.

The Visual Editor

Provides direct editing of:


Text
HTML elements
Data controls

The toolbar contains


formatting tools for:
Color
Text size
Format (style)

10-9

You can drag CSS


definitions to a page

Copyright 2004, Oracle. All rights reserved.

What Are Custom Tags?

Custom tags are developed in Java and defined


and used with XML syntax.
Tags are used in a JSP to reduce or constrain the
amount of Java scriptlets in the page.
Tags are useful for defining recurring tasks such
as accessing a database or sending an e-mail.
Custom tags are packaged into libraries:
Packaged as .jar files
Defined in a .tld file

10-10

Copyright 2004, Oracle. All rights reserved.

Utilizing Tag Libraries

Tag libraries are utilized in a JSP by:


Defining the location of the tag library using the
taglib directive

Creating a prefix to reference the tag library in the


JSP

<%@ taglib uri="http://java.sun.com/jstl/core"


prefix="c"%>

Using the prefix to call a tag and specifying


attributes as necessary

<c:out value="avalue"></c:out>

10-11

Copyright 2004, Oracle. All rights reserved.

JSP Standard Tag Library

The JSP Standard Tag Library (JSTL) is being


developed under the Java Community Process. It
provides a common and standard set of custom tags
for:
Iteration, conditional processing, and expression
language support
Parsing and transforming XML documents
Formatting and parsing strings, dates, and
currencies for internationalization
Database access and data manipulation

10-12

Copyright 2004, Oracle. All rights reserved.

Struts Tags

The Apache Struts technology contains


a custom tag library for use with JSPs.
There are several categories of Struts
libraries available in the Component
Palette, including:
Struts HTML
Logic
Struts Beans
Templates
Nested
Tiles

10-13

Copyright 2004, Oracle. All rights reserved.

Data Binding Tags

The Data Control Palette


contains objects that are
mapped to the workspaces
business components. The
controls may be included in the
JSP in different formats,
depending on the type of model
component they represent:
Input Text (Individual Item)
Input Form (Complete View
Object)
Button (Operation such as
Commit)

10-14

Copyright 2004, Oracle. All rights reserved.

Utilizing the Data Control Palette

10-15

Drag components from


the Data Control Palette
to the Visual Editor of a
JSP to display data.
Use the Drop As
list box to select the
style of the control.

Copyright 2004, Oracle. All rights reserved.

How Data Is Displayed

JSTL is used to iterate through and display data:


<c:out value="${expr}" />
<c:forEach var="Row" ></c:forEach>
<%@ taglib uri="http://java.sun.com/jstl/core"
prefix="c"%>
<table border="1" width="100%"><tr>
<c:forEach var="Row"
items="${bindings.OrdersView1.rangeSet}">
<tr><td>
<c:out value="${Row.currencyString}">
</c:out>
</td>

10-16

Copyright 2004, Oracle. All rights reserved.

View Object Control Types

Use view object component types to display all data in


a view object. Drop the view object as one of the
following types of controls:

10-17

Table
Dynamic Table
Navigation Buttons
Input Form

Read-Only Form
Select Row Link
Graph
Navigation List

Copyright 2004, Oracle. All rights reserved.

View Object Item Control Types

To display a data control that


represents a single view object item,
select the item in the Data Control
Palette and add it to the JSP as a:
Value
Label
Input Field
Password Field

10-18

Copyright 2004, Oracle. All rights reserved.

Operations

Operations are data actions that interact with an entire


view object or an entire application module. They
include:
Create: Creates a new row in the view object
Find: Navigate to a specific row in the view object
Delete: Deletes the current row
Execute: Submit a query
Navigation sets (First Set, Last Set, First, and
Next)
Commit: Commits an entire application module
Rollback: Rolls back changes on an application
module
10-19

Copyright 2004, Oracle. All rights reserved.

Customizing Controls

10-20

Select View > Property Inspector to modify the


control properties.
For operations, you may also double-click the
button to modify the name and value.

Copyright 2004, Oracle. All rights reserved.

JSP Versus UIX

An ADF view can also be created as a UIX page:


More visual components are available in UIX.
The Data Control Palette can be used to create
data-bound UIX pages.

10-21

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Create JSP pages that use scriptlets, expressions,
and declarations to generate dynamic content
Incorporate tag libraries in JSP pages to further
the component-centric design of JSP applications
Add ADF Business Components to a JSP via the
Data Control Palette

10-22

Copyright 2004, Oracle. All rights reserved.

Practice 10-1: Overview

This practice covers the following topics:


Creating a JSP for user login
Creating navigation to another JSP
Creating a JSP for editing and inserting customer
data

10-23

Copyright 2004, Oracle. All rights reserved.

Customizing Actions

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to


do the following:
Describe the Struts XML elements and structure
Describe the anatomy of an action
Use the execute method to enhance the behavior
of an action
Describe the use of form beans
Use a dynamic form bean

11-2

Copyright 2004, Oracle. All rights reserved.

Struts Configuration File

Is XML type file


Is the application resource descriptor
Is used by the servlet to determine actions to
perform
<struts-config>
<action-mappings>
<action path="/action1"/>
<forward name="success" path="/page1.do"/>
</action>
</action-mappings>
<message-resources
parameter="view.ApplicationResources"/>
</struts-config>

11-3

Copyright 2004, Oracle. All rights reserved.

Creating the Action Class

In the context menu, select Go to Code.


Or, double-click the action.
Specify a name for the action.

/auth

11-4

Copyright 2004, Oracle. All rights reserved.

Default Code of an Action

public class AuthUserAction extends Action


{
/* This is the main action called from the Struts
framework.*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
return mapping.findForward("success");
}
}

11-5

Copyright 2004, Oracle. All rights reserved.

Forwards
success

Forwards can be defined:


By using the Page Flow
Diagram
/authUser
In the XML file
In the Structure pane
failure

/page1

/page2

<action path="/authUser"
type="view.AuthUserAction">
<forward path="/page1.do" name="success"/>
<forward path="/page2.do" name="failure"/>
</action>

11-6

Copyright 2004, Oracle. All rights reserved.

ActionForward of an Action Class

The return parameter from ActionForward


specifies where to send control.
The default naming of a single forward is
success.
The execute() method can be customized:
Additional code can be added.
Other forwards can be specified.
Appropriate forward is done on conditional testing.

11-7

The forward name represents a logical name.


A forward can also be a global forward.

Copyright 2004, Oracle. All rights reserved.

Creating Global Forwards

A global forward is just like any forward, but it can


be accessed by any action.
The global forward is defined in the config file.
<global-forwards>
<forward name="help" path="/help.do"/>
</global-forwards>

The global forward is specified in the action class.


return mapping.findForward("help");

11-8

Copyright 2004, Oracle. All rights reserved.

Form Beans

Logon

User Name
Password
Logon

Submit
authUser
Populates

logonBean
menu

11-9

Copyright 2004, Oracle. All rights reserved.

Form Beans

A form bean is used to transport data between a


page and an action.
Can be static:
Is defined in a FormBean class
Contains set(), get(), and reset() methods for
each field
Contains a validate() method for verifying user
input

Can be dynamic:
Each field specified in struts.config.xml
Does not require Java code

11-10

Copyright 2004, Oracle. All rights reserved.

Creating a Static Form Bean

Create an action in the Page Flow Editor.


Right-click and select Go to Form Bean.
Specify a name (suffix the name with Form).

/authUser

A new icon is displayed.


/authUser

11-11

Copyright 2004, Oracle. All rights reserved.

Example: Static Form Bean

public class AuthUserActionForm extends ActionForm


{
String username;
public String getUsername()
{ return username; }
public void setUsername(String newUsername)
{ username=newUsername; }
public void reset(
public ActionErrors validate(
}

11-12

Copyright 2004, Oracle. All rights reserved.

Dynamic Form Beans

11-13

This is an alternative way for an action to have


access to incoming fields from a page.
The form bean class is not needed.
There is no need for getter and setter methods.
The field names are specified in the strutsconfig.xml file.
New fields can be added dynamically.

Copyright 2004, Oracle. All rights reserved.

Creating a Dynamic Form

1. Create a form bean from the Structure pane.


2. Specify
org.apache.struts.action.DynaActionForm
as the type for the bean.
3. Create a new form property for each field.
<form-bean name="logonBean"
type="org.apache.struts.action.DynaActionForm">
<form-property name="username" type="java.lang.String"/>

11-14

Copyright 2004, Oracle. All rights reserved.

Using the Bean in an Action

Using a static bean:


Create and cast the ActionForm type
Use the getXxx() method
AuthUserActionForm authForm = (AuthUserActionForm) form;
String username=authForm.getUsername();

Using a dynamic bean:


Cast the form object passed to the execute()
method to a DynaActionForm type
String
username=(String)((DynaActionForm)form).get("username");

11-15

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow

Logon

failure
authUser
success

<action-mappings>
<action path="/logon
forward="/logon.jsp"/>
<action path="/authUser"
name="logonBean"
type="view.AuthUserAction">
<forward
path="/logon.do
name="failure"/>
<forward
path="/menu.do
name="success"/>
</action>
<action path="/menu"
forward="/menu.jsp"/>
</action-mappings>

menu

11-16

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow: Struts Elements


<action-mappings>
<action path="/logon
forward="/logon.jsp"/>

Logon

failure
authUser
success

menu

11-17

<action path="/authUser"
name="logonBean"
type=" view.AuthUserAction ">
<forward
path="/logon.do
name="failure"/>
<forward
path="/menu.do
name="success"/>
</action>

<action path="/menu"
forward="/menu.jsp"/>
</action-mappings>

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow: Struts Elements


<action-mappings>
<action path="/logon
forward="/logon.jsp"/>

Logon

<action path="/authUser"
name="logonBean"
type=" view.AuthUserAction ">

failure
<forward
path="/logon.do
name="failure"/>

authUser
success

menu

11-18

<forward
path="/menu.do
name="success"/>
</action>
<action path="/menu"
forward="/menu.jsp"/>
</action-mappings>

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow: Form Bean


User Name

Logon

Password
Logon

failure

Submit

authUser
success
logonBean
menu

11-19

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow: Form Bean

Logon

failure

<form-beans>
<form-bean
name="logonBean
type="org.apache.struts.
action.DynaActionForm">

authUser
success

menu

11-20

<form-property
name="username"
type="java.lang.String"/>
<form-property
name="password"
type="java.lang.String"/>
</form-bean>
</form-beans>

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow


User Name

Logon

Password
Logon

failure

Submit

authUser
Passed to

Populates

success
logonBean
menu

11-21

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow: Action Class

public ActionForward execute(ActionMapping mapping,


ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
{
DynaActionForm LAF = (DynaActionForm) form;
String un = (String)LAF.get("username");
String pw = (String)LAF.get("password");
if (un.equals("Scott")) {
return mapping.findForward("success");
} else
return mapping.findForward("failure");
}

11-22

Copyright 2004, Oracle. All rights reserved.

Sample Page Flow


User Name

Logon

Password
Logon

failure

Submit

authUser
Passed to

Populates

success
logonBean
menu

11-23

Copyright 2004, Oracle. All rights reserved.

Form Beans, Data Actions, and Data Pages

ADF creates a form bean automatically when you


create:
Data actions
Data pages

The ADF Form Bean is called a DataForm.


DataForms do not require custom code:
No static form bean class is needed.
No dynamic form bean declaration is needed.

11-24

ADF uses these objects to manage form data.

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Describe the Struts XML elements and structure
Describe the anatomy of an action
Use the execute method to enhance the behavior
of an action
Describe the use of form beans
Use a dynamic form bean

11-25

Copyright 2004, Oracle. All rights reserved.

Practice 11-1: Overview

This practice covers the following topics:


Using the Page Flow Diagram
Adding data actions
Adding data pages
Creating form beans

11-26

Copyright 2004, Oracle. All rights reserved.

Using ADF Struts Components

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Describe data actions and data pages
Customize data actions and data pages to
enhance the behavior of an application
Use data actions to access multiple types of
business services
Describe the relationship between databound
pages and data pages

12-2

Copyright 2004, Oracle. All rights reserved.

What Are Data Actions?

Data actions are an extension of the action class,


which:
Are provided with Oracle ADF
Provide access to business services, such as
business components
Prepare the data and make it available for pages to
consume

12-3

Copyright 2004, Oracle. All rights reserved.

What Are Data Pages?

Data pages are an extension of the DataAction class,


which:
Are provided with Oracle ADF
Combine a data action and a page forward
Do not rely on forwards to forward application
data
Simplify the Page Flow Diagram

12-4

Copyright 2004, Oracle. All rights reserved.

Utilizing Data Pages

To use a data page, perform these steps:


1. Create the data page in the Page Flow Diagram.
2. Double-click to create the corresponding view
object (JSP, HTML, and UIX).
3. Define the Struts page flow as necessary.
4. Add business service methods to the data page as
necessary.

12-5

Copyright 2004, Oracle. All rights reserved.

Creating Data Pages

Drag a data page to /browseCustomer


the Page Flow
Diagram.
The strutsconfig.xml file is
updated with the
data action.
<action-mappings>
<action path="/browseCustomers"
className="oracle.adf.controller.struts.actions.DataActi
onMapping"
type="oracle.adf.controller.struts.actions.DataForwardAc
tion" name="DataForm" parameter="unknown"/>
</action-mappings>

12-6

Copyright 2004, Oracle. All rights reserved.

Creating the View Component

Double-click the data page to create


the view component.
/browseCustomer
<action-mappings>
<action path="/browseCustomers"
className="oracle.adf.controller.struts.actions.DataActi
onMapping"
type="oracle.adf.controller.struts.actions.DataForwardAc
tion" name="DataForm" parameter="/browseCustomers.jsp">
<set-property property="modelReference"
value="browseCustomersUIModel"/>
</action></action-mappings>

12-7

Copyright 2004, Oracle. All rights reserved.

Displaying Data

To display data from the data page, add elements from


the Data Control Palette:
Bound Data
Navigation
Operations
The data controls associated with the data action are
defined in DataBindings.cpx (created automatically).

12-8

Copyright 2004, Oracle. All rights reserved.

Displaying Data

Select elements from the Data Control Palette and drag


them to the page:

Generated code
<c:forEach var="Row"
items="${bindings.CustomersView1.range
Set}">
<tr><td>
<c:out value="${Row.CustomerId}">
</c:out></td>
12-9

Copyright 2004, Oracle. All rights reserved.

Modifying the Iterator

Click the UIModel icon in the Structure pane to locate


the iterator for the model. Then use the Property
Inspector to change the range size.

12-10

Copyright 2004, Oracle. All rights reserved.

Adding Methods to Data Actions

To perform DML with data actions, add methods to the


data action:
Drag to
data page icon
/browseCustomer

/addCustomer

<action path="/addCustomers"

<set-property property="methodName"
value="addCustomersUIModel.Create"/>
</action>

12-11

Copyright 2004, Oracle. All rights reserved.

Adding Methods to Data Pages

Drag and drop methods from the


Data Control Palette to add
methods to a data page:
Create

setCurrentRowWithKey

Delete

12-12

Copyright 2004, Oracle. All rights reserved.

Navigating in Data Pages

HTML Form tag submits to itself, by default.


Change the action to the page that receives the
form data.
Use the Property Inspector to change the value of
action.
Select the data page or
action that receives the
form data.

12-13

Copyright 2004, Oracle. All rights reserved.

Data Action Life Cycle


1. Initialize context
Get HTTP request

Get binding info

2. Build event list

8. Invoke custom methods

3. Check for model bindings

9. Refresh binding controls

4. Check if updates allowed

10. Dispatch to forward

5. Process updates
6. Validate updates
7. Handle model and UI events

12-14

Copyright 2004, Oracle. All rights reserved.

Customizing Data Actions

Data action methods may be customized to provide


functionality for:
A data action having two possible forwards:
protected ActionForward findForward() {
Object s = request.getParameter("Update");
if (s != null) {
return getActionMapping().findForward("success");
} else
return getActionMapping().findForward("browse"); }

Any custom functionality:


Protected void invokeCustomMethod(DataActionContext ac) {

12-15

Copyright 2004, Oracle. All rights reserved.

Data Action Events

Built-in operations are listed in the UIModel.xml file:

Defined by:
Dragging operation from the Data Control Palette
Explicit creation in the Structure pane

Invoked by:
Button with the name event_<operation>,
for example, event_Commit.
Hyperlink with a parameter event=< operation>,
for example, event=Commit.

12-16

Copyright 2004, Oracle. All rights reserved.

Data Action Events

Using built-in events, you can define your own


operations:
Defined by:

Invoked by:

12-17

Coding an on<CustEvent>() method in the data


action
Button with the name event_<CustEvent>,
for example, event_Help.
Button with the name event and value
<CustEvent>,
for example, name=event value=Help.
Hyperlink with a parameter event=< operation>,
for example, event=Commit.
Copyright 2004, Oracle. All rights reserved.

on<Event> Example: Built-in Events

Extending a named built-in event


?event=commit

public void onCommit(DataActionContext ctx)


{
HttpSession session = ctx.getHttpServletRequest().getSession();
Boolean loggedOn = (Boolean)session.getAttribute("AUTHFLAG");
if (loggedOn.booleanValue())
{
ctx.getEventActionBinding().doIt();
}
}

12-18

Copyright 2004, Oracle. All rights reserved.

on<Event> Example: Custom Events

Calling a custom operation


event=foo

public void onFoo(DataActionContext ctx)


{
// just direct the flow to the "foo" forward
ctx.setActionForward("foo");
}

12-19

Copyright 2004, Oracle. All rights reserved.

Forwards and Events in ADF Applications

Name related forward components


the same as the submit buttons to
submit first to the data page, then
to the forward target.
addCustomers.jsp:

<html:form action="/addCustomers.do">

<input name="event_Add" type="submit"


value="Submit"/>

12-20

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Create data pages mapped to business services
Create Web applications that utilize data pages
Customize data actions and data pages to
enhance the behavior of an application

12-21

Copyright 2004, Oracle. All rights reserved.

Practice 12-1: Overview

This practice covers the following topics:


Creating data actions
Adding methods to data actions

12-22

Copyright 2004, Oracle. All rights reserved.

Adding Validation and Error Handling

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Validate form input
Use declarative validation
Use client-side validation
Utilize control hints to modify the view

13-2

Copyright 2004, Oracle. All rights reserved.

Overview of Validation
Form Bean validate()
method, Struts Validator

JSP

JavaScript

13-3

Struts
Form Bean

Method Validators,
Control Hints

Struts
Action

ADF
Business
Components

New Validation Methods

Copyright 2004, Oracle. All rights reserved.

Need for Validation

In Web applications, the user usually does not receive


training on how to complete fields correctly. Thus, an
application must provide feedback to the user for
these types of actions:
Entering required values
Specifying values within a specified range
Comparing values
For example, Password1 must match Password2.

13-4

Copyright 2004, Oracle. All rights reserved.

Client-Side Validation

To perform validation by using Struts, you must:


1. Create a form bean class
2. Overwrite the form bean validate() method,
passing an error to the action
3. Create the error message in
ApplicationResources.properties
4. Add the input attribute for the form to the action to
indicate where the error message should appear

13-5

Copyright 2004, Oracle. All rights reserved.

Form Bean Validation Method

The form bean contains a validate() method for


validating form fields. Overwrite this method to
perform custom validation:
public ActionErrors validate(ActionMapping
mapping, HttpServletRequest request)
{
ActionErrors errors = new ActionErrors();
if ((username == null) ||
(username.trim().equals("")))
{
errors.add("username", new
ActionError("error.username.required"));
}
return errors;
}
13-6

Copyright 2004, Oracle. All rights reserved.

Creating the Error Message

To display the error message, specify the


message in
ApplicationResources.properties:
error.username.required=The Username Value must be
Supplied

Define where the error message is to be displayed


by using the input attribute:
<action name="logonbean" path="/logon"
input="showLogon.jsp" type="view.LogonAction">

13-7

Copyright 2004, Oracle. All rights reserved.

Printing Errors in the JSP

Ensure that the JSP contains an <html:errors> tag:


<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ page contentType="text/html;charset=windows-1252"%>
<html>

<body>
<html:errors />

Note that you can specify the property attribute of the


<html:errors> tag to print only the corresponding
error:
<html:text property="username"></html:text>
<html:errors property="username" />

13-8

Copyright 2004, Oracle. All rights reserved.

Validating Actions

A second type of validation is to overwrite the execute


method in the action class. This type of validation is
useful when:
You have previously created classes that check
the validity of a given value
You do not want the form values to be reset after
validation
The validation logic is complex

13-9

Copyright 2004, Oracle. All rights reserved.

Creating a Validation Class

The first step in validating user input is to create a


method for validation. This can be done in a simple
class file, as shown:
package view;
public class LoginValidation
{
boolean checkUsernamePassword(String un, String pw)
{
if ( un.equals("scott") && pw.equals("tiger") )
return true;
else
return false;
}
}

13-10

Copyright 2004, Oracle. All rights reserved.

The execute() Method

To validate user input in the action class, overwrite the


execute() method, calling your validation method:
public ActionForward execute
{
LogonActionForm logonForm = (LogonActionForm) form;
String un = logonForm.getUsername();
String pw = logonForm.getPassword();
LoginValidation loginvalidation = new
LoginValidation();
if ( loginvalidation.checkUsernamePassword(un,pw))
{
return mapping.findForward("success");
} else return mapping.findForward("failure"); }

13-11

Copyright 2004, Oracle. All rights reserved.

Validation Results

1. User enters incorrect


2. User enters no data
login (action validation).
(form bean validation).

3. User enters correct


login.

13-12

Copyright 2004, Oracle. All rights reserved.

Struts Validator

Declaratively validate form fields by using the Struts


Validator. The validator plug-in:
Is XML based
validator-rules.xml (Validation rules)
validations.xml (Usages)

13-13

Defines rules for each field in a form bean


Can provide client validation using JavaScript
Is extensible

Copyright 2004, Oracle. All rights reserved.

Setting Up the Struts Validator

1. Specify the validator class in the <plug-in> tag of


struts-config.xml.
2. Add validation-rules.xml to your project.
3. Modify the form bean class to subclass
ValidatorForm or DynaValidatorForm.
4. Create a usage file to specify form field rules.
5. Add error messages to
ApplicationResources.properties.

13-14

Copyright 2004, Oracle. All rights reserved.

Utilizing the Struts Validator

Add ValidatorPlugIn to the <plug-in> tag and


specify the path for validator-rules.xml and
validation.xml:

13-15

Copyright 2004, Oracle. All rights reserved.

Utilizing the Struts Validator

Specify the form bean to use the Struts Validator


by subclassing ValidatorForm or
DynaValidatorForm:
import org.apache.struts.validator.ValidatorForm;
public class LogonActionForm extends ValidatorForm {

Create validation.xml to validate form fields,


and ensure that each form field to be validated
contains an entry in
ApplicationResources.properties:
Logon.username=username
Logon.password=password

13-16

Copyright 2004, Oracle. All rights reserved.

validation.xml: Example

<!DOCTYPE form-validation PUBLIC


"-//Apache Software Foundation//DTD Commons
Validator Rules Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd
">
<form-validation>
<formset>
<form name="logonbean">
<field property="password" depends="required" >
<arg0 key="logon.password" />
</field>
</form>
</formset>
</form-valiidation>

13-17

Copyright 2004, Oracle. All rights reserved.

Struts Validator Output

Validator messages can be displayed on the page or in


a JavaScript window:

13-18

Copyright 2004, Oracle. All rights reserved.

Exception Handling

Exception handling is implemented by:


1. Creating a class for exception handling, which
subclasses
org.apache.struts.action.ExceptionHandler

2. Overriding the execute() method to process the


exception
3. Returning an ActionForward object
4. Configuring the exception handler in the strutsconfig.xml file
5. Creating an exception message in
ApplicationResources.properties

13-19

Copyright 2004, Oracle. All rights reserved.

JavaScript

JavaScript is supported
in JDeveloper as a
simple way to
incorporate validation.

13-20

Copyright 2004, Oracle. All rights reserved.

Enhancing the View

Use control hints


to modify the way
an attribute is
displayed in a
client.

13-21

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Validate form input using:
The validate() method
The action class
The Struts Validator

13-22

Develop JavaScript validation


Customize the view by using control hints

Copyright 2004, Oracle. All rights reserved.

Practice 13-1: Overview

This practice covers the following topics:


Validating form fields by using the validate()
method
Creating validation methods
Calling validation methods from actions
Utilizing the Struts Validator
Handling exceptions

13-23

Copyright 2004, Oracle. All rights reserved.

Enhancing the User Interface

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Use the Property Inspector to modify visual
components
Use the Structure pane to modify data elements
Add navigational elements

14-2

Copyright 2004, Oracle. All rights reserved.

Modifying Visual Component Properties

To change the appearance of an object in the Visual


Editor, you can use:
Formatting toolbar of the HTML/JSP Visual Editor:

14-3

Property Inspector:

Copyright 2004, Oracle. All rights reserved.

Using the Toolbar to Format Objects

Style
poplist

Font
poplist

Font
size

Bold/
italic/
underline

14-4

Foreground
color

Align left/
center/right

Background
color

Numbered/
bulleted
list

Copyright 2004, Oracle. All rights reserved.

Decrease/
increase
indent

Using the Property Inspector

The Property Inspector:


Displays attributes of the selected tag or tags
Displays intersection or union of attributes for
multiple selected tags
Visually distinguishes
changed attributes

14-5

Copyright 2004, Oracle. All rights reserved.

Adding Images to JSPs

To add images to JSPs, drag an image file to the


Visual Editor:

14-6

Copyright 2004, Oracle. All rights reserved.

Using Style Sheets

You can use the following types:


Style sheets available in JDeveloper:
Oracle
Browser Look and Feel (BLAF)
JDeveloper

14-7

Style sheets that you add to the Component


Palette

Copyright 2004, Oracle. All rights reserved.

Editing Default Style Sheets

To modify an existing style sheet, open it in the Code


Editor:
Code insight is
available for CSS
files.
Saving the file
updates the CSS
for the current
application
workspace.

14-8

Copyright 2004, Oracle. All rights reserved.

Creating a New Style Sheet


New Gallery

CSS File

Create Cascading Stylesheet


HTML

untitled1.css

14-9

Copyright 2004, Oracle. All rights reserved.

Editing Style Sheets

14-10

Copyright 2004, Oracle. All rights reserved.

Adding a Style Sheet to the


Component Palette
To add a style sheet:
1. Select CSS from the pop-up
list.
2. Right-click in the Component
Palette.
3. Select Add Component.
4. Click Browse to choose file.
5. Enter name.

14-11

Copyright 2004, Oracle. All rights reserved.

Applying a Style Sheet to a Page

14-12

Copyright 2004, Oracle. All rights reserved.

Adding Buttons to a JSP

Form action buttons: Submit and Reset


Data control buttons
Model: Commit and Rollback
View: Navigation and DML

14-13

Copyright 2004, Oracle. All rights reserved.

Adding Data Control Buttons

Data control buttons:


Are added to JSP
from Data Control
View
Palette
operations
Are related to data
on the page
When related to
view, can control
Model
operations
navigation or initiate
DML
When related to model, can commit or rollback

14-14

Copyright 2004, Oracle. All rights reserved.

Adding Navigation Buttons


Data Control Palette

DepartmentsView1

Drop As:
Navigation Buttons

14-15

Copyright 2004, Oracle. All rights reserved.

Adding Form Action Buttons

Cursor

14-16

Copyright 2004, Oracle. All rights reserved.

Supplementing Button Functionality

14-17

Use button events.


The form action plus
defined events are
performed.

Copyright 2004, Oracle. All rights reserved.

Using Expression Language

Expression Language is:


Used in combination with JSTL tags
A way to provide dynamic content without scripts
or JSP expressions
Using a JSP expression to access an attribute:
<x:aTag att=
"<%= pageContext.getAttribute("aName") %>">

The simpler syntax of Expression Language:


<x:aTag att= "${aName}">

14-18

Copyright 2004, Oracle. All rights reserved.

Using EL Attributes

To reference attributes:
Enclose within ${}
Nest by using dot notation or []

Optionally include scope

<c:out value=
"${sessionScope.cart.numberOfItems} ">

14-19

Copyright 2004, Oracle. All rights reserved.

Using EL Literals and Operators

Literals: Values not beginning with ${

<c:out value="Hello ${customer.firstName}"/>

Operators

<c:if test="${bean1.a

14-20

< 3}" />

Copyright 2004, Oracle. All rights reserved.

Using EL Implicit Objects


When referenced by name, the appropriate object is
returned instead of the corresponding attribute.
Examples:
${pageContext} returns the pageContext
object.
${pageContext.request.contextPath} returns
the context path (obtained from
HttpServletRequest).
${sessionScope.cart.numberOfItems} returns
the numberOfItems property of the sessionscoped attribute named cart.
${param["mycom.productId"]} returns the
String value of the mycom.productId parameter.
14-21

Copyright 2004, Oracle. All rights reserved.

Using EL to Customize a Page

You can add conditional display logic using EL


For example, display a message and value only if the
value is not empty.

14-22

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Use the Property Inspector to modify visual
components
Use the Structure pane to modify data elements
Use EL to add conditional display logic

14-23

Copyright 2004, Oracle. All rights reserved.

Practice 14: Overview

This practice covers the following topics:


Modifying visual elements of a JSP
Using the formatting toolbar
Using the Property Inspector

14-24

Adding navigation buttons to a JSP


Adding a button to a JSP that invokes an external
Web page
Creating a style sheet and applying it to the JSP

Copyright 2004, Oracle. All rights reserved.

Adding JAAS Security to the Client

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Describe how Java Authentication and
Authorization Services (JAAS) works in a Web
application
Use JAAS to add security to an application
Add users and roles to an application deployment
descriptor
Add JAAS security to a Web application

15-2

Copyright 2004, Oracle. All rights reserved.

JAAS Provider

The JAAS provider supports:


Storage, retrieval, and administration of:
- Realm information (users and roles)
- Policy (permissions)
Multiple repositories:
- XML based
- LDAP based
Login modules

It works with J2EE declarative security model:


Is part of the deployment model
Requires little or no programming

15-3

Copyright 2004, Oracle. All rights reserved.

Defining Security Needs

Determine the logical roles in an application:


Customer
Buyer
Administrator

Determine authorization constraints: Who can do


what actions.
Decide provider type:
XML- based flat file
LDAP (Oracle Internet Directory)

15-4

Map security roles to users and groups.

Copyright 2004, Oracle. All rights reserved.

Oracle JAAS Implementation: JAZN

OracleAS Containers for J2EE (OC4J) implement a


JAAS provider called JAZN.
The Oracle provider supports:
Integration with single sign-on (SSO)
Access control through Java 2 permissions
Secure file-based storage of user passwords

JAZNUserManager
Obfuscates passwords in flat file storage
Supports full role-based access control
Supports full support for Java 2 permissions model

15-5

Copyright 2004, Oracle. All rights reserved.

Client Authentication

Authentication:
Determines who clients are
Can they prove it?

JAAS integrates any number of authentication


schemes, for example:
SSO: Uses OracleAS Single Sign-On
SSL: Uses secure sockets layer (SSL) for client
certificate-based authentication
Basic authentication: Prompts for username and
password
Write your own login module.

15-6

Copyright 2004, Oracle. All rights reserved.

Client Authorization

15-7

Client authorization is specified in J2EE


deployment descriptors.
Every client obtains a security principal.
A client can invoke a URL or a method only if the
clients role has the associated rights.
The J2EE container enforces security policies and
provides tools for managing security.
Struts includes roles at the node level.

Copyright 2004, Oracle. All rights reserved.

Basic Authentication Scenario


Oracle Containers
for J2EE
WebApp
HTTP client

Servlet 1 Servlet 2

OracleAS

JAAS

JAZNUserManager
JAAS
HTTP Server

15-8

OracleAS
JAAS Policy

Copyright 2004, Oracle. All rights reserved.

OracleAS
JAZN Provider

Adding JAAS Security to an Application

JDeveloper provides a dialog box to help add


JAAS security to an application.
By using the dialog box, you do not have to
directly edit the XML files.
Security settings are maintained in the web.xml
file.
Access the settings:
Right-click web.xml in the Applications Navigator.
Select properties from the context menu.

15-9

Copyright 2004, Oracle. All rights reserved.

Adding Authorization Information to Struts

15-10

The Struts configuration includes an authorization


scheme.
The scheme specifies authorization at the node
level.
Specify the authorized role
in the Property Inspector.

Copyright 2004, Oracle. All rights reserved.

web.xml Properties

To implement JAAS security, modify:


Security roles: Add the security role that you want
to use.
Add a Web resource:
Specify any unique name.
Add a URL pattern to validate.
On the Authorizations tabbed page, select the user
role.

15-11

Copyright 2004, Oracle. All rights reserved.

web.xml Results

<web-app>

<security-constraint>
<web-resource-collection>
<web-resource-name>TestApplication</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>users</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>users</role-name>
</security-role>
</web-app>

15-12

Copyright 2004, Oracle. All rights reserved.

Adding Users and Roles

15-13

JDeveloper provides a wizard interface to the


jazn-data.xml file.

Select Tools > Embedded OC4J Server Preferences.

Copyright 2004, Oracle. All rights reserved.

Adding Users

15-14

Copyright 2004, Oracle. All rights reserved.

Managing Roles

15-15

Copyright 2004, Oracle. All rights reserved.

Selecting a Specific jazn-data.xml File

JDeveloper allows you to specify which JAZN file


to use at runtime in the application configuration.
To change files:

15-16

Right-click the application module


Select configurations
Edit the jbo.security.config property
Enter the path to your jazn-data.xml file

It gives you testing and deployment flexibility.


To use LDAP, change the jazn.xml file.

Copyright 2004, Oracle. All rights reserved.

Running the Application

15-17

Test the application.


The browser prompts
for username and
password.
The application is
opened if the user is
authenticated and
authorized.
If either fails, the
application is not
authorized to run.

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Use JAAS to add security to an application
Add users and roles to an application deployment
descriptor
Add JAAS security to a Web application
Describe how JAAS works in a Web application.

15-18

Copyright 2004, Oracle. All rights reserved.

Building ADF UIX View Components

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Describe the characteristics of ADF UIX
Define the structure of a UIX XML page
Build a UIX XML page
Add components to a UIX XML page
Create data-centric pages with data components
Run and test a UIX XML page

16-2

Copyright 2004, Oracle. All rights reserved.

Why ADF UIX Technologies?

Design-time benefits

Run-time benefits

16-3

WYSIWYG/Declarative development environment


Open, flexible framework
Customization
Streamlined design workflow
Standards
Platform independence
Internationalization and accessibility support
High interactivity

Copyright 2004, Oracle. All rights reserved.

What are ADF UIX Technologies?

ADF UIX Technologies are a framework based on the


MVC model.
UI Components

Servlet

View

Controller

Model
Any data source

16-4

Copyright 2004, Oracle. All rights reserved.

How Do ADF UIX Technologies Work?

1. ADF UIX components are assembled.


2. They are rendered into Markup pages.
3. They are delivered to a variety of clients.

UIX Page

16-5

Markup

Copyright 2004, Oracle. All rights reserved.

UIX XML Page Layout

1.
2.
3.
4.
5.

16-6

Page Header
Tabs and Navigation
Global Buttons
Data Component Area
Page Footer

Copyright 2004, Oracle. All rights reserved.

Interface Nodes

Each page is divided into a hierarchical set of nodes,


each node corresponding to a specific section of the
page.

16-7

Copyright 2004, Oracle. All rights reserved.

How Is It coded?
UIX XML is a dialect of the XML language for creating ADF
UIX pages declaratively.

16-8

Copyright 2004, Oracle. All rights reserved.

Support for Internationalization

UIX supports client-specific renderers, which:


Are portable to different locales, fonts platforms,
and browsers
Process text separately from images (local
imaging)
Use run-time cascading style sheets with
environment style information

16-9

Copyright 2004, Oracle. All rights reserved.

User Interface Components

UIX XML pages are composed


of interface components, which
can be classified into three
types:
Simple
Layout
Composite

16-10

Copyright 2004, Oracle. All rights reserved.

Modular Declarative Design

16-11

Copyright 2004, Oracle. All rights reserved.

Creating a UIX XML Page

16-12

Copyright 2004, Oracle. All rights reserved.

Company and Product Branding

16-13

Copyright 2004, Oracle. All rights reserved.

Page Tabs

16-14

Copyright 2004, Oracle. All rights reserved.

Global Buttons

16-15

Copyright 2004, Oracle. All rights reserved.

Page Footers

16-16

Copyright 2004, Oracle. All rights reserved.

Designing with the Visual Editor

16-17

Copyright 2004, Oracle. All rights reserved.

Coding with the XML Editor

16-18

Copyright 2004, Oracle. All rights reserved.

UIX XML Page at Run Time

16-19

Copyright 2004, Oracle. All rights reserved.

Adding Data to the Page


ADF Business Components are a type of data
components that can be added to a UIX XML page.

16-20

Copyright 2004, Oracle. All rights reserved.

Design Time Data Components

16-21

Use the Data Control


Palette to include the
data components on the
page.
Modify the prompts or
other attributes with the
Property Inspector.

Copyright 2004, Oracle. All rights reserved.

Data Binding in the Visual Editor

16-22

Copyright 2004, Oracle. All rights reserved.

Run-Time UIX XML Page with Data Binding

16-23

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Define and discriminate the ADF UIX XML
components
Construct a UIX XML page by using the wizards
Include data items on a page from the model
Run and test a UIX XML page

16-24

Copyright 2004, Oracle. All rights reserved.

Practice 16: Overview

This practice covers:


Creating a UIX XML page
Adding ADF Business Components
Running the page using OC4J

16-25

Copyright 2004, Oracle. All rights reserved.

Deploying an ADF Application

Copyright 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to do


the following:
Create a remote OracleAS Containers for J2EE
(OC4J) Connection in JDeveloper
Configure OC4J for application deployment
Use the JDeveloper Deployment Wizard to deploy
to OC4J
Run a JSP application in OC4J

17-2

Copyright 2004, Oracle. All rights reserved.

Overview

Servlet/JSP/HTML

Packaging

Libraries, Packages
17-3

Copyright 2004, Oracle. All rights reserved.

Deployment

Overall Considerations for Deployment

Packaging and distributing involves:


Class files
Libraries
HTML files

17-4

How you set up the deployment environment


depends on the server.

Copyright 2004, Oracle. All rights reserved.

J2EE Archive Format

17-5

Archive Type

Module Type

Software Content

Java Archive (JAR)

J2EE client module

Java Application
components

EJB JAR

J2EE EJB module

Enterprise
JavaBeans (EJB)
components

Web Archive (WAR)

J2EE Web module

Servlets and
JavaServer Pages
(JSP) components

Enterprise Archive
(EAR)

Not applicable

J2EE application

Copyright 2004, Oracle. All rights reserved.

Deploying to a Web Server

17-6

Copy the files with the extensions .jsp, .html,


.gif, to the document root directory of the Web
server.
Archive class files in an archive (.JAR, .WAR) file.
Set the class path of the Web server to point to the
archive files.

Copyright 2004, Oracle. All rights reserved.

Deploying to OC4J

OC4J is a J2EE-compliant Web server, included with


OracleAS 10g. To deploy to OC4J, perform the
following:
1. Install OC4J.
2. Start the remote OC4J server by issuing the
following from a command prompt:
<oc4j directory> java jar oc4j.jar
3. Create an OC4J Connection in JDeveloper.
4. Deploy the project by right-clicking
webapp1.deploy and selecting Deploy.

17-7

Copyright 2004, Oracle. All rights reserved.

Install OC4J

1. Open a command window.


2. Navigate to <ias_Home>/j2ee/home.
3. Run the following command:
% java -jar oc4j.jar -install

This command unpacks and installs OC4J.


4. Enter a password for the OC4J administrator
account.

17-8

Copyright 2004, Oracle. All rights reserved.

Start the OC4J Server

To start the OC4J server, use the following from the


OC4J home directory, usually
<iAS_Home>/j2ee/home
% java -jar oc4j.jar

The server can be stopped by using the following


command:
% java -jar admin.jar ormi://localhost/
<admin> <password> -shutdown

17-9

Copyright 2004, Oracle. All rights reserved.

Creating an OC4J Connection

17-10

Copyright 2004, Oracle. All rights reserved.

Creating an OC4J Connection

17-11

Copyright 2004, Oracle. All rights reserved.

Creating a Deployment Profile

Creating a deployment profile enables you to specify


how the J2EE application is deployed:

17-12

Copyright 2004, Oracle. All rights reserved.

Deploying to OC4J

17-13

Copyright 2004, Oracle. All rights reserved.

Running Applications

To run the deployed application, call the following


URL:
http://hostname:8888/<workspacename><projectname>-context-root/main.jsp

The context root can be customized in the deployment


profile.

17-14

Copyright 2004, Oracle. All rights reserved.

Customizing Deployment

To change the names of directories used in


deployment, double-click the .deploy file.

17-15

Copyright 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Package the applications that you develop for
deployment in a Web server
Create an OC4J connection in JDeveloper
Deploy your application to the Oracle9i
Application Server

17-16

Copyright 2004, Oracle. All rights reserved.

Practice 17-1: Overview

This practice covers the deployment of an ADF BCbased JSP application.

17-17

Copyright 2004, Oracle. All rights reserved.

Course Schema

Copyright 2004, Oracle. All rights reserved.

Practice Solutions

Copyright 2004, Oracle. All rights reserved.

Vous aimerez peut-être aussi