Extend Applications to Mobile Browsers with ADF Mobile
Extend Applications to Mobile Browsers with ADF Mobile
You can work in JDeveloper's IDE to create a JSF application targeted for Mobile Device Browsers.
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
an application for ADF Mobile.
Create a database connection: Use
the Create Database Connection dialog to create a connection to the
schema.
Create Oracle ADF Business Component objects:
Use the Create Oracle ADF Business Components wizard to create the
business components that will provide access to data and implement the
business logic.
Edit the View Object : Modify the View Object to include only the fields necessary for the application.
Add Validation Logic: Add validation rules to the Entity Object.
Test the Application Logic in the Business Component Tester:
Use the Business Component Tester to test the application logic components created in the previous steps.
Set the Screen Size:
Use the Preferences dialog to set the default screen size for target mobile devices.
Create the ADF Mobile Project: Create the ViewController project for an ADF Mobile Application, and select the appropriate technology scope.
Create the Page Flow: Create the page flow for the ADF Mobile application.
Create a JSF Page: Create a JSF Page for mobile devices to browse orders by double clicking on the page in the Page Flow Editor.
Create a Browse Page: Define the JSF for browsing orders in mobile device browsers containing a read-only form and a table.
Create an Edit Page: Define the JSF for browsing orders in mobile device browsers containing a form to edit orders.
Run the Application: Run the application in a mobile device simulator.
Optimize the Layout:
Set the properties for the various fields on the view layout to ensure
fields are displayed on a mobile device screen with minimal scrolling.
Create a Static View Object: Create a static view object for the order status values.
Create a Static LOV:
Create a static LOV for the order status field on the Edit Order form,
so the order status description is displayed in a drop-down list box.
Create a Lookup View Object:
Create a lookup view object for the Customer ID field, so customer
names can be displayed instead of the ID in the Edit Order view.
Create a Dynamic LOV:
Create a dynamic LOV for the Customer ID field on the Edit Order form,
so the customer name is displayed in a drop-down list box.
Test the LOV: Run the application after LOVs are added to the Edit Order view.
.
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...]
If
you have previously completed the creation of the ADF Business
Components for the Fusion Order Demo, you may skip ahead to the Set the ADF Mobile Preferences cue card.
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 . Under Resources
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 The /jdeveloper directory
where you have JDeveloper installed, for example, c:/JDeveloper_11/jdeveloper/
jdbc.urlBase Base
URL 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.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."
When prompted, enter the password for the database user with admin privileges.
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...]
From the File menu, chooseNew.
Select Applications in the Categories pane and then Generic Application in the Items pane.
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...]
Click OK.
Enter the short name for the application using all lower-case letters (for this example, enter adfm).
In the Application Package Prefix field, enter oracle.fod.mobile and then click Next.
Enter a short name for the project using all lower-case letters (for this example, enter model).
Select ADF Business Components In the Available pane of the Project Technologies tab and shuttle it to the Selected Technologies pane.
Click Next twice and the click Finsh.
In the Application Navigator, expand the Application
Resources panel to see where resources for this
application are displayed.
In
the IDE
In
creating this application, you use the Create Generic Application
wizard. You can use this wizard to create both an ADF Mobile
application and project. After you open the wizard by selecting Applications and then Generic Applications in the New
Galery, the first page opens where you enter the name of the mobile
application and the Application Package Prefix: [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 and fod for
the username.
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 move 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 tab, 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.
On the General page click
Add next to Entity
Validation Rules.
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 popup.
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 Business Component Browser - Connect 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 2007-01-14,
enter 2007-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 2007-01-14,
enter 2007-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...]
Set the Screen Size
Setting the Screen Size
JDeveloper
enables you to set the visual editor to the dimensions of a mobile
device screen. In the example below, the screen size of the
visual editor is set to 240X320 Pixels. This provides a visual
aid in designing pages for mobile browsers. [tell me more...]
Click ToolsPreferences.
Select Mobile
and then select 240 x 320
as the default screen size for the visual Editor. Selecting a
default
screen size provides visual aid when creating views for mobile devices,
but it does not affect the runtime behavior of the application.
Views would typically adjust to the viewport size of the
device when they are displayed.
Click OK.
In the IDE
The Preferences dialog enables you to set the default size of the visual
editor to give you an approximation of how the components fit on a
mobile device screen. [tell me more...]
Create an ADF Mobile Project
Creating an ADF Mobile Project
A JDeveloper project is used to logically group files that are
related. A project keeps track of the source files, packages, classes,
images, and other elements that your program may need. You can add
multiple projects to your application to easily access, modify, and
reuse your source code. [tell me more...]
From the File
menu, choose New.
In the New Gallery, select Project
from the Categories
pane and then Generic Project
from the Items pane.
Click OK.
Enter mvc as the name of the
project. (mvc stands for "Mobile" View
Controller) and then click Next.
Naming Mobile Applications and Projects
Entering short, lower-case names for ADF Mobile applications and projects creates a shorter URL, which is easier to enter from a mobile device. [tell me more...]
Shuttle Mobile
from the Available pane
to the Selected pane.
Click Next
twice and then click Finish.
In the IDE
When you move Mobile from the Available pane to the Selected
pane, Java, JSF (JavaServer Faces), JSP (JavaServer Pages) and Servlets
are also shuttled to the pane. When you add Mobile technology, the
Apache My Faces Trinidad library is automatically loaded to the
workspace and the Trinidad component palette will be loaded when you
create mobile JSF pages. [tell me more...]
Create the Page Flow
Creating the Page Flow
The mvc ("mobile" view-controller) project in the application contains
a default JSF page flow, faces-config.xml. A page
flow includes the JSF pages and page navigation rules
that define an application's page flow. [tell me more...]
In the Application Navigator, expand the mvc project.
Click faces-config.xml
(located in the WEB-INF folder).
Choose JSF Diagram
Objects from the Component Palette.
Select
JSF Page in the Component Palette and by dropping it onto
the form in the visual editor.
Name the JSF page /br-o. This
page is a browse order page, the the first application page which
represents the default activity.
Create an edit order page by selecting JSF Page in the
Components Palette and then by dropping it onto the the form in the
visual editor.
Name the page /ed-o.
Create the page flow by selecting
JSF Navigation Case in the Components Palette.
Connect the pages by first clicking /br-o
and then /ed-o in the visual editor.
Enter goEdit on the outcome
label of the JSF Navigation Case.
Select a
JSF Navigation Case from the Component palette.
In the visual editor, select /ed-o
and then /br-o to
connect the pages.
Enter goBrowse on the outcome
label of the JSF Navigation Case.
In the IDE
The page flow contains two JSF pages: browsing orders and editing
orders, which are represented by the /br-o and /ed-o JSF pages. These
pages are connected using the JSF Navigation Case components. [tell me more...]
Create a JSF Page
Creating a JSF Page
The pages you create for your web application using JavaServer
Faces are JSP documents
(which have the file extension .jspx) or JSP
pages (which have the file extension .jsp). [tell me more...]
In the visual editor, double-click /br-o
to open the Create JSF Page dialog.
Accept the file name /br-o.jspx
and then click OK.
(Because Mobile technology scope is selected during Project creation, the Render
in Mobile Device option is selected by default.)
Select Trinidad from the Component Palette.
Select
Panel Header from the Component Palette and drop it
directly inside h:form in the Structure view for /br-o.jspx. Update the Text property of the Panel Header component to Browse Order.
Select
Panel Group Layout from the Component Palette and drop it
into the visual editor.
Change the layout by selecting vertical
from the Layout property's dropdown list in the Panel Group Layout's
Property Inspector.
Designing the User Interface
To create the user interface, add Apache MyFaces Trinidad components
to the JSF pages. [tell me more...]
Enter Browse Order as the text
property in the Panel Header's Property Inspector.
In the IDE
The visual design of br-o.jspx is displayed
in the visual editor, and the Structure window shows the page's
structure. As you add components to the page, you
will drop them inside the panelGroupLayout component, and their arrangement
will be controlled by the layout manager of the panelGroupLayout component. [tell me more...]
Create a Browse Page
Creating a Browse Page
The browse page enables a user to view
and navigate through the data objects
one at a time. Both a read-only form and read-only
table will be added to supply the master/detail functionality
in this browse page. You will add
components to the br-o page, to browse orders and
order items. The orders are shown one at a time,
with the order information in a read-only form and the
order's line items in a table. [tell me more...]
In the Application Navigator, expand the Data Controls
panel and then the
FODModuleDataControl node.
Drag the OrdersView1
node into the panelGroupLayout
in the Structure view.
Choose FormsTrinidad
Read-Only Form from the Create menu.
Data Control Panel and UI Controls
The Data Control panel comprises a hierarchical display
of available business objects, methods, and data control
operations. [tell me more...]
In the Edit Forms Field dialog, select all of the fields
except for OrderId, OrderDate, OrderStatusCode, OrderTotal, and
Customer ID and then click Delete.
If needed, clear the Include
Navigation Controls check box and then click OK.
In the Structure view, expand panelGroupLayout.
Select the OrderId field
(Panel-Label And Message - #{bindings.OrderId.hints.label}).
In the Label field of the Property Inspector, append a
colon (:) and two spaces after the populated value to improve
legibility.
Repeat this step for the OrderDate,
OrderStatusCode, OrderTotal, and CustomerId fields.
Click Save
All.
Create a button called First for the browse page by first
expanding the Operations
folder in the Data Controls pane and then by selecting First.
Drag and drop this button directly beneath h:form in the Structure view.
This button is inside the form, but ouside of the Panel Group Layout.
Select Trinidad Button
from the context menu.
Repeat this process to add Previous,
Next, and Last buttons to the form.
In the Trinidad Components Palette, select Command Button
and then drop it directly beneath the Last
button in the form.
In the Command Button's Property Inspector, enter Edit
as the Text property.
Select goEdit from the Action
property drop-down list.
In the Data Controls panel, expand the OrdersView1 node and then drop
it at the bottom of the form in the Structure view.
Choose TablesTrinidad
Read-Only Table from the Create menu.
In the Edit Table Columns dialog, select Sorting.
Delete all of the columns except for LineItemId, Quantity, UnitPrice, and ProductName and then click OK.
In the Structure view, expand tr:table.
Select the LineItemId
column (tr:column-#{bindings.OrderItems1View2.hintsLineItemId.label}).
Enter ID for the Header Text
property in the Property Inspector.
Repeat this process to rename the Quantity column as Quan.,
the UnitPrice column as Price, and the
ProductName as Name.
Select tr:table
in the Structure view and then enter 100% for
the Width property.
Click Save
All.
In the IDE
The visual editor shows the read-only form, table and buttons
that make up your page, and the Structure view shows the
hierarchy of the components
in the page. You can reorganize the page
structure by dragging components in the Structure view, or
moving them in either the visual editor or source editor. [tell me more...]
Create an Edit Page
Creating an Edit Page
ADF drag and drop databinding allows you to bind visual
components on a page to data or to actions. You will use
both techniques: you will create a form to edit orders
data; and you will bind a button to the commit action.
[tell me more...]
In the Application Navigator, click faces-config.xml
(located in the WEB-INF folder).
In the visual editor, double-click /ed-o
to open the Create JSF Page dialog.
Accept the file name /ed-o.jspx and then click OK. (Because mvc is an ADF
Mobile project, the Render in Mobile
Device option is selected by default.)
Select Trinidad
for the Component Palette.
Select Panel Header
from the Component Palette and drop it directly inside the h:form in the
Structure view for /ed-o.jspx.
Enter Edit Order as the Text
property in the PanelHeader's Property Inspector.
Select
Panel Group Layout from the Component Palette and drop it
into the visual editor.
Change the layout by selecting vertical
from the Layout property's dropdown list in the Panel Group Layout's
Property Inspector.
In the Application Navigator, expand the Data Controls
panel and then the FODModuleDataControl
Node.
Drag the OrdersView1
node into the PanelGroupLayout in the Structure view.
Choose Forms Trinidad Form
from the Create menu.
Click OK in
the Edit Form Fields dialog.
In the Data Controls panel, expand the Operations folder
and then select the Commit
operation.
Drag and drop in the Commit operation directly below h:form in the Structure view.
Commit Operations
By dragging the commit operations from the data control
panel onto the page, you create a button that saves
the transaction on the editing page and also a button that returns the user to the browsing page. Note that while each data collection contains
its own set of operations such as next, previous, create,
and execute, the commit and rollback operations apply to
all data in the data control. [tell me more...]
Choose Trinidad Button
from the Create menu.
In the Property Inspector, enter Save
as the Text property and then select Reset
to Default for the Disabled property.
Select
Command Button from the Component Palette and drop it
directly beneath the Save button in the Structure view.
In the Property Inspector, enter Return
as the Text property and then select goBrowse from the Action property drop-down list.
Click Save
All.
In the IDE
When you create your edit page, the page should look like
this in the visual editor: [tell me more...]
Run the Application
Running
the Application
The
JDeveloper IDE includes a Java EE runtime service for packaged archive
deployment called Integrated WLS. Based on zero-copy deployment,
Integrated WLS lets you run and test an application and its projects as
a Java EE application in a Java EE container. Integrated WLS server
instances can be bound to applications and then started, stopped, and
debugged. [tell me more...]
In the editor window, click br-o.jspx to bring it forward.
Right-click within the form and then choose Run.
In the running application, use the navigation buttons to
change the current row and note the changing details in the OrderItems
table.
Start the emulator for the mobile device of your choice.
Running
an Emulator
To test an ADF Mobile application using an emulator, enter your
computer's IP Address into the application URL, in place of the
localhost reference. Device emulator cannot resolve the localhost
reference as it simulates a network device, so you must substitute the
localhost reference with the IP address of your computer. Other than
the host name, the remainder of the application URL is correct. For
example, enter http://<IP Address>:<Port Number>/adfm-mvc-context-root/faces/br-o.jspx in the device browser. [tell me more...]
Connect the emulator's browser to Oracle JDeveloper.
In the IDE
When you run the br-o.jspx page, it should look
similar to this page in your browser: [tell me more...]
Optimize the Layout
Optimizing the Layout
In
this step, you optimize the layout of both the .jspx pages for display
on mobile devices by restricting the number of rows that display on
browsing page and the field width on the editing page.
Furthermore, you specify the display of the views to take up the
entire viewport on the mobie device. This allows UI components to
remain viewable even with increased screen resolution. [tell me more...]
Open br-o.jspx
in the visual editor.
Select the table.
In the Property Inspector,
enter 2
for the Rows property.
In the Structure view, expand f:view, and then
expand trh:html.
Right mouse click on trh:head
- Browse Order item, and select Insert HTML/JSP menu item.
Copy and paste the following line into the text box. Remove any extra brackets as necessary, then close the text box. <meta
name="viewport" content="width=device-width; initial-scale=1.0;
maximum-scale=1.0; user-scalable=0;"/>
Open ed-o.jspx in the visual editor.
In the Structure view, expand h:form
and then expand tr:panelFormLayout.
Select the OrderId,
CustomerId, ShipToAddressId, and ShippingOptionId inputText
fields.
In the Property Inspector, enter 5
for the Columns property.
In the Structure view, select the OrderDate,
OrderShippedDate, OrderTotal, ShipToName, ShiptoPhoneNumber, and GiftwrapMessage inputText fields.
In the Property Inspector, enter 12
for the Columns property.
In the Structure view, expand f:view, and then
expand trh:html.
Right mouse click on trh:head
- Edit Order item, and select Insert HTML/JSP menu item.
Copy and paste the following line into the text box. Remove any extra brackets as necessary, then close the text box. <meta
name="viewport" content="width=device-width; initial-scale=1.0;
maximum-scale=1.0; user-scalable=0;"/>
ClickSave
All.
In the IDE
When you first open the br-o.jspx, the table component contains the defualt
number of rows. [tell me more...]
Create a Static View Object
Creating
a Static View Object
A static LOV is based on a view object where transient
attributes are created and populated at design time. You
will define a view object, populate it with the static
values needed for the LOV and associate it with the view
object that will use it as an LOV. [tell me more...]
In the Application Navigator, select the model project
and launch
the Create View Object wizard [File > New > Business Tier > ADF Business Components > View Object] .
Enter StatusCodes as the name of the view object.
Select Rows populated at design time
(Static List),
and click Next.
On step 2, click New. In the
New View Object Attribute dialog, enter StatusCodes as
the name of the attribute and select Key Attribute. Then click OK.
Click New again. Enter StatusDesc as
the name of the attribute and click OK.
Then click Next twice.
On step 4, click Add seven
times to create the static list values. Enter values and descriptions
for StatusCodes and StatusDesc, for example:
PENDING Order submitted SHIP Order is being shipped PICK Order is being picked COMPLETE Order complete CANCEL Order cancelled STOCK Waiting for stock CART Order in cart
Click Next to display
the Application Module page. Select Application
Module to have the new view added to the FODModule application
module. Then click Finish.
Defining
a Static List of Values
When you define a static list for a view object, JDeveloper
creates a standard message bundle file in which to store
them. The file is specific to the view object component
to which it is related, and it is named accordingly. Internationalizing
the model layer of an application built using ADF Business
Components entails producing translated versions of each
component's message bundle file. For example, the Italian
version of the ModelBundle.properties message
bundle would be a class named ModelBundle_it.properties,
and a more specific Swiss Italian version would have the
name ModelBundle_it_ch.properties. [tell me more...]
In the editor window, click the OrdersView.xml tab
to bring the page forward, and select the View
Accessors tab.
To set the StatusCodes view
object, click Add.
Select StatusCodes in the Available View Objects pane and
shuttle it to the View Accessors pane.
Then click OK.
Select the Attributes tab, then
select the OrderStatusCode attribute.
Click Add next
to the List of Values item.
In the List of Values dialog, fully expand the OrdersView
| StatusCodes nodes, and select the StatusCodes attribute.
Accept the default name.
Click Edit List UI Hints. Select StatusDesc in
the Available pane
and shuttle it to the Selected pane.
Select Selection Required from the "No
Selection" Item dropdown
list.
Click OK again to close the List of Values dialog.
Click Save all.
In the IDE
When you add the view object as a view accessor, it
should look like this: [tell me more...]
Create a Static LOV
Creating a Static LOV
A static LOV is based on a view object where transient
attributes are created and populated at design time. You
will assign the view object to a specific attribute that
requires an LOV and choose how the LOV will be displayed.
You then edit a page to display the attribute as an LOV
list.
[tell me more...]
In the editor window, click the ed-o.jspx tab
to bring the page forward.
Select the OrderStatusCode inputText field
and delete it.
In the Data Controls
panel, expand the FODModuleDataControl|
OrdersView1 node.
Select the OrderStatusCode attribute
and drop it directly beneath the OrderShippedDate inputText field (its previous location) in the Structure View.
From the Create context menu,
choose Single Selection
Trinidad
Select One Choice.
Model Driven List
The status codes are displayed as a choice list in
the LOV UI. With a choice list, other options
are available: you can display multiple columns in the
LOV (in this example, the status code); and also allow
the user to leave the selection blank. You also could have
used a different LOV UI, for instance a combo box or a
radio group. [tell me more...]
Click Save all to save your work.
In the IDE
In the edit page, an LOV is available next to the OrderStatusCode field: [tell me more...]
Create a Lookup View Object
Creating a Lookup View Object
A dynamic LOV is based on a view object which provides
the SQL to populate the list of values. You will define
the view object and specify the query that will used as
the basis for the LOV in this case, retrieving all the
customers. Once you've configured a view object to provide
a list of values for a given field, you can easily allow
that list to be used for validation. In this example, you
can ensure that the CustomerId value that a user enters
in the editOrders form is a valid CustomerId, that is,
a value that is in the list of values.
[tell me more...]
In the Application Navigator, select the model project
and launch
the Create View Object wizard [File > New > Business Tier > ADF Business Components > View Object] .
Enter CustomerView as the name of the view
object.
Select Read-only access through SQL query. Then click Next.
On step 2, enter the following in the Query
Statement box: SELECT * from PERSONS Persons
WHERE Persons.PERSON_TYPE_CODE = 'CUST'
Click Test to test the query.
Then click Next until
you reach step 6: Attribute Settings.
On step 6, select the PersonId attribute and select Key
Attribute. Then click Next until
you reach step 8: Application Module.
On step 8, select Application Module.
Then click Finish.
In the Application Navigator, double-click Orders in
the Model project to open it
in the editor, and select the View Accessors tab.
Lookup View Objects
The new view object can be added as a view accessor in
the View Accessors dialog, available by clicking the View
Accessors tab in the overview editor. [tell me more...]
Click Add to
open the View Accessors dialog. Select CustomerView in
the Available View Objects panel
and shuttle it to the View Accessors panel.
Then click OK.
Select the Attributes tab,
then select the CustomerId attribute.
Click Add next
to the Validation Rules item.
In the Add Validation Rule dialog, select Key
Exists Validator from the Rule
Type drop down list.
Select View Accessor from
the Validation Target Type drop
down list.
Select CustomerId in
the Available Entity Attributes panel
and PersonId (under CustomerView)
in the Validation
Target Attributes panel. Click Add.
Then click OK.
Click OK to continue without
defining an error message.
In the IDE
You created a view object that can be used as
the provider for a list of values in the user interface.
That view object also serves as a list of valid values
in the validation of the CustomerId field. [tell me more...]
Create a Dynamic LOV
Creating a Dynamic LOV
You will use the dynamic view object (a view object populated
from a SQL query) created earlier as the basis for a list
of values. You will remove the CustomerId field
from the form, and replace the field with an inputListOfValues component.
This component displays as an input text field, with a
button next to it which can be activated to display the
list of values in a separate window. You will configure
the list of values to display a subset of columns from
the view object, and specify the relationship between the
field and the value selected from the list
[tell me more...]
In the editor window, click the OrdersView.xml tab
to bring it forward.
Select the Attributes tab.
Select the CustomerId attribute
and click Add next
to the List of Values item, to
create an LOV for this item.
In the List of Values dialog, expand Orders.CustomerView and
select PersonID.
Click Edit List UI Hints.
Select
the following attributes in
the Available pane and
shuttle them to the Selected pane,
in this order: FirstName, LastName.
Click OK twice to close
both dialogs.
Click the ed-o.jspx tab
to bring the page forward.
Select the inputText field for CustomerId and
delete it.
Dynamic LOVs
Using the Data Controls panel, you can add the List of
Values for CustomerId to the
page, replacing the inputText field
for CustomerId after you
delete it. [tell me more...]
In the Data Controls panel, expand the FODModuleDataControl|
OrdersView1 node.
Select the CustomerId attribute
and then drop it directly below the OrderTotal inputText field (its
previous location) in the Structure view.
From the Create context menu,
choose Single Selections Trinidad Select One Choice.
In the Property Inspector for the Select One Choice for CustomerId, enter CustomerName for the Label property.
In the IDE
You added an selectOneChoice component
to the ed-o.jspx form.
Clicking on the button activates the list of values, from which
you can select a value for the field from a user-friendly interface. [tell me more...]