You can easily install the schema and connect to the database,
and then create an application and project in which to
organize your application files. Then work in JDeveloper's
IDE to create the business services for your application.
Install the Schema: Download the schema
zip file from OTN and install it. The cue cards use tables
that are part of the Fusion Order Demo (FOD) schema.
Create a New Application: Use the Create
Application dialog to create a web application based on
the application template that includes the ADF Faces, ADF
Page Flow, and ADF Business
Components technologies.
Create a Database Connection: Use the Create Database Connection dialog to create a connection to the schema.
Create Oracle ADF Business Components: Use
the Create Oracle ADF Business Components from Tables wizard
to create the business components that will provide access
to data and implement the business logic.
Edit the View Object: Use the Attributes
and Entity Objects pages in the view object editor to modify
the view object.
Add Validation Logic: Add validators in the Add Validation Rule dialog.
Test the application: Test the application
in the Business Component tester.
Install the Schema
Installing the Schema
The steps and examples in the cue cards are based on tables
that are part of the Fusion Order Demo (FOD) schema. This
schema is also used as the database for the sample application
that ships with Oracle JDeveloper 11g, as well as other
collateral in this release. It will be convenient to have
this schema installed, and you only need to do it once.
If you have already installed the FOD schema, you can skip
this step and go directly to the next card. [tell me more...]
Unzip the file to a convenient location (for example, c:\temp).
From the File menu,
choose Open. Open the
workspace c:\temp\Infrastructure\infrastructure.jws.
If you are prompted to migrate the project, click Yes to confirm.
In the Application Navigator, expand the MasterBuildScript project and
double-click build.properties to open it in the editor.
Set the appropriate values in the build.properties file
(jdeveloper.home, and all the jdbc.* and db.* settings).
Keep all other properties set to their default values. The
demo user must be named FOD.
The relevant
settings are:
jdeveloper.home Location
where you have installed JDeveloper, for example, c:/JDeveloper/11g
jdbc.urlBase Base
URI for your database, for example, jdbc:oracle:thin:@localhost
jdbc.port Port
number for your database, for example, 1521
jdbc.sid Database
System Identifier, for example, XE or ORCL
db.adminUser Database
user with admin privileges, for example, system
db.adminUser.password Password for database
user with admin privileges, for example, manager
db.demoUser.tablespace Tablespace name where the
FOD user will be installed, for example, USERS
In the MasterBuildScript project,
select the build.xml file.
In the Structure window, right-click the refreshSchema target
and choose Run
Target "refreshSchema."
In the IDE
After running the Ant task, you should see a build
successful
message in the JDeveloper Log window. [tell me more...]
Create a New Application
Creating a New Application
The JDeveloper application is the highest level in the organizational
structure. It stores information about the objects you are
working with, while you are creating your application. It keeps
track of your projects and the environment settings while you
are developing.
[tell me more...]
Open the Create Application dialog [File > New > General > Applications > Application] .
Enter the application name BrowseEditApp to follow
along with the example.
In the Application Package Prefix field, enter oracle.fod.
Select Fusion Web Application
(ADF) from the Application
Template dropdown list, and click OK.
Application Templates
Application templates provide you with a quick way to create the
project structure for standard applications with the appropriate
combination of technologies already specified. The new application
created from the template appears in the Application Navigator already
partitioned into tiered projects, with the associated technology scopes
set. The application template you select determines the initial project
structure (the named project folders within the application) and the
application libraries that will be added. The project templates define
the associated technologies. You can modify existing templates or
create new ones. You can then filter the work you do in JDeveloper such
that the choices available are focused on the technologies you are
working with. [tell me more...]
In the Application Navigator, expand the Application
Resources panel to see where resources for this
application are displayed.
In the IDE
The application template that you used for your application
partitions your application
into two projects: Model and ViewController.
In the Application Navigator, projects are displayed as
the top level in the hierarchy. The
Application Navigator should now look like this: [tell me more...]
Create a Database Connection
Creating a Database Connection
You can connect to any database for which you have connection
details, or install the sample schema used in the cue card
examples and then establish a connection to it. If you
installed the sample schema, you will be able to follow
the steps in the cue cards exactly as written. If you work
with your own database, you can supply your own values
as needed. [tell me more...]
Open the Create Database Connection dialog [File > New > General > Connections > Database Connection] .
Select Application Resources if
it is not selected as the Create Connection
In option.
Enter a name for the connection, select the connection
type, and enter the username and password.
To follow along with this example, use FOD for
the connection name, fod for
the username and fusion for the password.
Click Test Connection to
confirm that you can connect.
Click OK if the connection was successful.
In the Application Navigator, expand the Connections and
Database nodes in the Application
Resources panel to see
the database objects.
In the IDE
The database
connection is now included as a resource for your application. [tell me more...]
Create Oracle ADF Business Components
Creating Oracle ADF Business Components
Oracle ADF Business Components is a model layer technology
in the Oracle Application Development Framework (Oracle
ADF). Oracle ADF Business Components is a fully-featured,
XML-based framework for creating business services. That
is, it governs interaction between the rest of the application
and the data stored in the datasource, providing validation,
specific services, and other business logic. [tell me more...]
In the Application Navigator, select the Model project
and launch the Create Business Components from Tables wizard [File > New > Business Tier > ADF Business Components > Business Components from Tables] .
In the Initialize Business Components Project dialog, confirm
that the database connection you created (for example, FOD)
is the current selection and click OK.
On step 1, Entity Objects, of the Business Components from
Tables wizard, click Query to
populate the Available list.
Select three tables, ORDERS, ORDER_ITEMS and PRODUCTS_BASE,
from the Available list
and shuttle them to the Selected list
to create default business components based on them. Then
click Next.
On step 2, Updatable View Objects, select business components,
Orders (FOD.ORDERS) and OrderItems
(FOD.ORDER_ITEMS), from the Available list
and shuttle them to the Selected list.
Then click Next.
Click Next to skip step
3, Read-Only View Objects, which aren't needed.
On step 4, Application Module, change the application module
name to FODModule. Then click Finish.
ADF Business
Components
The Create Oracle ADF Business Components from Tables
wizard does not create a user interface (this is governed
by the "view" portion
of the application), nor does it determine other application
logic such as control flow. It just provides a representation
of, and access to, data, and implements business logic. [tell me more...]
Click Save all to save your work.
In the IDE
After completing the Business Components from Tables wizard,
the Model project in the Application
Navigator should look like this: [tell me more...]
Edit the View Object
Editing the View Object
A view object's main role is typically to fetch the data
to be displayed by a client. You
will modify the default view
objects that you created earlier to reflect the data that
will be displayed in your web pages. [tell me more...]
In the Application Navigator, double-click OrdersView in
the Model project
to open it in the view object editor.
Select the Attributes tab to
display all the attributes in the OrdersView view
object.
In the attributes table, select the following attributes: PaymentOptionId,
DiscountId, CouponId, CollectionWarehouseId, CreatedBy, CreationDate, LastUpdatedBy, LastUpdateDate, and ObjectVersionId.
Then click Delete.
Removing
Attributes
By removing attributes from the OrdersView view object you have reduced the number of columns in the view object's query. [tell me more...]
In the Application Navigator, double-click OrderItemsView in
the Model project
to open it in the view object editor.
Select the Entity Objects tab.
Select ProductsBase in the Available pane and
shuttle it to the Selected pane.
Entity
Objects
A view object can be based on more than one entity object;
you do this if you need your client pages to show data
from multiple tables. In the list of order items on the
client page you will show each item's id, quantity and
price, from the OrderItems entity object, as well as the
product name, from the ProductsBase entity
object. [tell me more...]
Select the Attributes tab. To
add the ProductsBase attributes
to the OrderItemsView object,
click Add from Entity.
In the Attributes dialog, select the following attributes
under the ProductsBase node in the Available pane:
CategoryId, ProductName,
and WarrantyPeriodMonths. Shuttle the attributes
to the Selected pane.
Then click OK.
In the IDE
The OrdersView view object now contains attributes from
both the Orders entity object and the ProductsBase entity
object. Notice that OrderItemsView now
contains two ProductId attributes: ProductId from
the OrderItems entity object
and ProductId1 from the ProductsBase entity
object; this is necessary to specify the join between the
two entity objects. [tell me more...]
Add Validation Logic
Adding Validation Logic
You can add validation logic to enforce a rule, in this
case the rule that an order's ship date must occur after
the date the order was placed. You will create your validation
rule using ADF BC's declarative validation capabilities,
and define the logic using the Groovy scripting language. [tell me more...]
In the Application Navigator, double-click Orders in
the Model project to open it
in the entity object editor.
Select the Validators tab.
Select Orders and then click Add.
In the Add Validation Rule dialog, select Script Expression
from the
Rule Type dropdown list.
On the Rule Definition tabbed
page, enter OrderShippedDate
== null || OrderShippedDate >= OrderDate in
the Expression panel. Click Test to
verify the expression, and click OK when
you see the expression syntax check message.
Select the Failure Handling tab.
Click Add to
add a row to the first table.
Change the default Message Id to Orders_10.
Change the default Message String to {0}
cannot be earlier than {1}. Then press Enter or
Tab.
In the table below, enter the error
message expressions. For Message
Token 0, enter
source.hints.OrderShippedDate.label as the Expression. For Message
Token 1, enter
source.hints.OrderDate.label. Then click OK.
In the IDE
You have created a custom error message for your validation
rule; the {0} and {1} are placeholders
for parameters that you will define as the labels of the OrderShippedDate and OrderDate attributes.
ADF Business Components allow you to create custom labels
for each attribute; these labels are stored in message bundles
that can be translated for different locales, and they are
automatically displayed as the attribute's label on client
pages. In this example you have not defined custom labels,
so the labels default to the names of the attributes. [tell me more...]
Test the Application in the Business Component Tester
Testing the Application in the Business Component Tester
You can test the validation rules you added, in the ADF
Business Components Tester. The tester is a dynamically
generated Swing client that allows you to test your business
components. It is useful for testing any enhancements,
such as validation rules, LOVs or custom methods, that
you have added to your business components; it is also
a useful troubleshooting tool because it helps to narrow
down problems by removing any client code from the picture. [tell me more...]
In the Application Navigator, right-click FODModule and
choose Run.
In the Select Business Component Configuration dialog,
click Connect.
In the Business Component Browser, double-click OrdersView1.
Browse through the orders until you reach an order
without an OrderShippedDate.
Enter a new order shipped date that is earlier than
the order date. For example, if the order date is
2008-01-14, enter 2008-01-13 for
the order shipped date.
Click the Next icon to
navigate to the next record. Click OK when you see the error dialog containing your error
message: OrderShippedDate cannot
be earlier than OrderDate.
Change the order shipped date so that it is later
than the order date. For example, if the order date is 2008-01-14,
enter 2008-01-15 for the order shipped
date, so that no error dialog displays.
Click Commit to save your
changes.
Close the Business Component Browser.
In the IDE
After entering valid data, the tester shows the data that you have just saved to the database: [tell me more...]