Place
the cursor over this icon to load and view all the screenshots for this tutorial.
(Caution: This action loads all screenshots simultaneously, so response time
may be slow depending on your Internet connection.)
Note: Alternatively, you can place the cursor over
an individual icon in the following steps to load and view only the screenshot
associated with that step. You can hide an individual screenshot by clicking
it.
Overview
In this tutorial, you use ADF Business Components to develop
business services for viewing the products and orders in the Fusion Order Demo
sample application.
Start JDeveloper by selecting Start >
All Programs > Oracle WebLogic > JDeveloper Studio 11.1.1.0.0
JDeveloper will begin initializing.
Select Default Role when you are prompted by the role
dialog and click OK.
In the Configure File Type Associations box, select
all the checkboxes, then press OK.
Click No when you are prompted to migrate from a previous
release.
2.
Close the Tip of the Day and Updates dialog boxes.
3.
In the next few steps, you create the database
schema for the tutorial using an ant script that you run from JDeveloper.
First, download the Infrastructure.zip
to a temporary location on your hard drive.
In the file explorer, right click on the file Infrastructure.zip
and choose Winzip > Extract to...
4.
In the extract dialog, enter the folder where you
want to extract the Infrastructure workspace (eg: c:\oracleFusion\tutorial).
You may extract the file elsewhere, but ensure that you do not extract
it to a location containing a space anywhere in the path.
5.
Next, open the workspace in JDeveloper that contains
the build scripts.
In the Application Navigator, choose Open Application.
Browse for the location where you extracted the Infrastructure.zip
in the previous step. Select Infrastructure.jws and
click Open.
6.
There are four projects in this workspace. Projects
are logical groupings of files where you store work in JDeveloper. Expand
the MasterBuildScript project.
7.
Expand the Resources node and double
click build.properties in the Application Navigator
to open the file in JDeveloper's editor. This file contains settings
that are used to run the ant script.
8.
Modify the following values in the build.properties
file to point to your environment's unique settings, using a forward
slash as indicated below):
Click the Save icon in the toolbar to save the file.
9.
In the Application Navigator, right click build.xml
in the MasterBuildScript project and choose Run Ant Target
-> buildAll.
You will see JDeveloper's integrated Ant Log window appear, and then
another window will appear prompting you for your database system password.
Enter it and click Continue. If you do not see this
window and the Ant log is stopped at "setProperties:", minimize
JDeveloper, the window is probably hidden behind JDeveloper.
You will see several messages, including a harmless error. When you
see the following text, the "FOD" schema has been successfully
installed.
Develop Business
Services using ADF Business Components
To build business components for the persons, products, orders,
and order items tables, perform the following steps:
1.
First, create a new workspace for the application.
In the Application Navigator, select the dropdown next to the Infrastructure
workspace and choose New Application...
2.
In the first step of the wizard, Create Application, name the Application
FusionOrderApp. Enter the directory where you want
to store the workspace and all its related files, e.g., c:\oracleFusion\tutorial\FusionOrderApp.
Click Finish.
3.
In the second step of the wizard, Create Project, set the Project
Name to ADFBC_Model, and click OK.
4.
In the Application Navigator, right-click the ADFBC_Model
project and select New... from the context menu.
In the New Gallery, expand Business Tier and select ADF Business
Components in the Categories list.
Select Business Components from Tables in the Items list.
Click OK.
5.
In the Initialize Business Components Project dialog, click the
green plus to create a new connection.
In the Create Database Connection dialog, provide the following details,
leaving all other values as their defaults:
Connection Name
FOD
Username
fod
Password
fusion
JDBC Port
1521, or your port, if different
SID
XE, or your SID, if different
Click Test Connection to ensure the connection details
are correct.
Click OK to exit the Create Database Connection dialog,
and click OK again to continue developing business
components.
6.
In step 1 of 6 of the Create Business Components from Tables wizard,
set the package name to adfbc_model.entities.
Click Query to populate the list of available tables.
Control-click to select ORDERS, ORDER_ITEMS,
PERSONS, PRODUCTS_BASE, and PRODUCT_IMAGES
in the Available list.
Click the Add button to shuttle the tables to the Selected list.
Click Next to continue.
7.
On step 2 of 6, set the package to adfbc_model.queries
. This logically separates the persistent objects (entities) from the
queryable objects (views).
Click the Add All button to shuttle all objects
to the Selected list.
Click Next.
8.
On step 3 of 6, click Next. You will be using only view objects
that can be updated.
9.
On step 4 of 6, click the Application Module checkbox if
it is not already checked. Name the package adfbc_model.service,
and name the application module FusionOrderApp.
Click Next.
10.
JDeveloper provides several different techniques for managing components.
One is to use a diagram of the components and their relationships. In
this step, you can choose to have JDeveloper create a diagram of the
components that you are creating.
On step 5 of 6, select the Business Components Diagram
checkbox and accept the default package and name.
Click Next to continue.
11.
The final page of the Business Components Wizard shows the objects
and relationships that are created when you click Finish.
Click Finish to complete the wizard.
12.
To test the default business components you've created, in the Applications
Navigator, expand Application Sources and adfbc_model.service.
Right click FusionOrderApp and choose Run.
13.
Click Connect to connect to the FOD connection.
14.
You will see some warning messages in the message log, but the Business
Components Browser should still appear in a new window. In the resulting
Business Components Browser window, double click OrdersView1
to see all orders placed. Use the arrows to scroll through the rows
of orders. Double click the OrderItemsOrdersFkLink1
view link nested beneath OrdersView1. This link was created because
of the foreign key relationship between OrderItems.OrderId and Orders.OrderId
relationship defined in the database schema. This view of the link displays
all order items for each order record.
Close the Business Components Browser when you are finished.
To complete the application scenario, some modifications to
the wizard-generated business components need to be made.
1.
First, expand adfbc_model.entities
in the Application Navigator and notice the table-based entities OrderItems,
Orders, Persons, etc. Double click OrderItems to open
it in the editor.
Click the Attributes node in the
editor and notice that all table columns for the Order_Items table have
been added to the entity. You can modify the attributes (such as providing
validation), add attributes from other tables, and add non-persistent
(transient) attributes from this dialog.
2.
Double click the Quantity Attribute
to open the attribute editor.
In the Edit Attribute dialog, click the Validation
node. Click New... to create a new validation rule
for the Quantity attribute (the schema-based validation rules for the
attribute have already been added to the validation rules).
Select Range from the Rule Type dropdown.
Select Between as the Operator and enter a Minimum
Value of 1 and Maximum Value 10.
Click the Failure Handling tab.
3.
Select the Error radio button
to indicate that processing should stop upon validation failure. In
the Message Text window, click the magnifying glass icon to select the
text from a resource bundle.
In the Select Text Resource dialog, specify the value Please
enter a quantity between 1 and 10. Enter entities.OrderItems.Quantity.error
as the Key.
Enter any description text.
Click Save and Select.
Click OK twice to return to the OrderItems entity
editor. This validation rule will be applied each time a new quantity
is entered using this business component entity. Additionally, regardless
of the type of client used to create the UI, the internationalizable
error message string will be used to notify the user of the error. In
a real application, you would add many more validation rules to complete
the application's business logic. If the declarative validation rules
(such as Compare, Length, and Range) do not handle your application's
validation needs, you can also use Groovy scripts, Regular Expressions,
or Java methods to implement validation rules for an entity or its attributes.
4.
Now add a transient attribute to the OrderItems
entity to calculate the Order Item's total price based on the quantity
and unit price.
In the Attributes tab of the OrderItems entity, click the green plus
icon to add an entity attribute.
In the New Entity Attribute dialog, enter LineItemTotal
as the Name. Choose Number as the Type.
Deselect the Persistent checkbox. The attribute will
be calculated from an expression and not persisted in the database.
Select Expression as the Value Type. Click Edit
to create the expression.
In the Edit Expression Editor dialog, enter the following groovy script
as the expression
Select Always to always recalculate this expression.
Shuttle Quantity and UnitPrice to
the Selected region to allow these attribute names to be used in the
expression.
Click OK to exit the expression editor and again to
create the new entity attribute.
Click Save All in the toolbar to save your work.
5.
Now add the LineItemTotal attribute to the OrderItemsView
view object. In the Application Navigator, expand adfbc_model.queries
and double click OrderItemsView to open it in the editor.
Click the Attributes node in the
editor and click Add from Entity...
Select the LineItemTotal transient
attribute and shuttle it to the selected column.
Click OK.
6.
Expand adfbc_model.entities in
the Application Navigator and notice the table-based entities OrderItems,
Orders, Persons, etc. The relationships between entities are called
Associations and are named <DetailEntityMasterEntity>FkAssoc by
default.
In this tutorial's scenario, there is a relationship between ORDERITEM.PRODUCT_ID
and PRODUCTS_BASE.PRODUCT_ID that was not created automatically. You
might choose to add this relationship using the Business Components
Diagram, but in this case, use the declarative features of the ADF framework
to complete the task.
Right click adfbc_model.entities
and choose New Association...
7.
In the Create Association dialog, accept the default
package name and enter ProductsBaseOrderItemsFkAssoc
as the Name.
Click Next.
8.
In the Select Source Attribute panel, expand OrderItems
and select the ProductId attribute. In the Select Destination
Attribute panel, expand ProductsBase and select the
ProductId attribute. Click Add to
create an association between these two attributes of the OrderItems
and ProductsBase entities.
Click Next twice and then click Finish
to create the association.
Click Save All to save your work.
9.
View objects are "slices" of data, and
contain queries of one or more entity object attributes. View objects
can also be based entirely on a SQL query. In the case of the wizard-generated
view objects, there is one view object per entity object, which selects
all attributes for that entity. Your application might select only a
subset of those attributes, or you might have multiple view objects
based on one entity, to allow for multiple queries of that same data.
To see the view objects that were created, expand adfbc_model.queries
in the Application Navigator.
Notice that OrderItemsView, OrdersView, PersonsView, etc. are listed,
as are the view links between them. The wizard generated one view link
per foreign key association. Now add a view link for the association
you created in the previous step.
Right click adfbc_model.queries and choose New
View Link...
10.
In the Create View Link dialog, accept the default
package name and enter ProductsBaseOrderItemsFkLink
as the name.
Click Next.
11.
In the Select Source Attribute panel, expand OrderItemsView
and select ProductsBaseOrderItemsFkAssoc. In the Select
Destination Attribute panel, expand ProductsBaseView
and select ProductsBaseOrderItemsFkAssoc. Click Add
to create a view link based on the association.
Click Next twice and then click Finish
to create the association.
12.
View objects and links define how data may be viewed.
Clients (either web, mobile, or Swing) that access view objects do so
by accessing a data model. The data model in ADF is stored in an Application
Module. An application module, therefore, is one type of service. You
might have clients which utilize data from other services as well, such
as a web service or EJB. In the case of ADF, you have already seen the
Business Components tester which allows you to test the data model.
To define the data model further, expand adfbc_model.service
in the Application Navigator and double click FusionOrderApp
to open the application module editor.
Select the Data Model tab in the editor. Notice the
master objects ProductsBaseView1, ProductImagesView1, OrderItemsView1,
etc. listed on the right hand side of the Data Model editor. The high
level view objects have a "1" appended because they are the
first instance of a particular view object. For the dependent view objects
(those based on a view link), the instance number increases accordingly.
For example, OrdersView1 is the master object of OrderItemsView2, which
is related via a view link.
Now add a new instance to this OrderItemsView2 instance for the ProductsBaseOrderItemsFkLink
you created in a previous step. Select OrderItemsView2
on the right hand side of the editor. On the left hand side of the editor,
expand OrderItemsView and select ProductsBaseView
via ProductsBaseOrderItemsFkLink. The editor displays what
the name of the instance will be named in the New View Instance field,
in this case, ProductsBaseView2. To demonstrate that you can name these
instances as you like, change the New View Instance name to OrderItemProductDetail.
Finally, shuttle the instance to the right to add it to the data model.
You've now created and exposed a data model that will automatically
link the queries for Orders, Order Items and Product Details.
13.
Next you further customize the view objects for
the application's needs. In this case, we want to view Orders for a
particular customer, so that when a customer logs into the application,
they see only the orders they've placed.
In the Application Navigator, expand adfbc_model.queries
and double click OrdersView to open the view object
editor. Select the Query tab and click the pencil icon
in the top right of the editor to modify the query.
14.
In the Query editor, enter the following in the
Where clause:
Orders.CUSTOMER_ID
= :custId
15.
Click the Bind Variables node to
define the custId bind variable. Click New and in the
Variable tab, specify custId as the
Name and Number as the Type.
Select the Control Hints tab and enter Customer
Id as the Label Text. The label will be used for each
UI component that binds to this variable.
Click OK to modify the view object's where clause.
Click Save All to save your work.
16.
To test the modifications you've made in the data model, run the
business components tester. Right click FusionOrderApp and
choose Run.
17.
Click Connect to connect to the FOD connection.
18.
In the resulting Business Components Browser, double click OrdersView1.
Since you created a bind variable, the tester prompts you to provide
a value. Enter 108 and click OK.
19.
Use the arrows to scroll through the rows of orders.
Double click the OrderItemsOrdersFkLink1 view link
nested beneath OrdersView1, and click OK to use the same bind variable
value.
Double click the link you just created, ProductsBaseOrderItemsFkLink1
to view the product data for the currently selected order and order
item. The ProductsBaseView contains many attributes, so you may need
to resize the window and columns in order to view the data.
Close the Business Components Browser when you are finished.
You have built business services that will be used to create
the client application for the Fusion Order Demo sample. In the next lesson,
you will expose these services and create the user interface for the sample.