Part 1: Create the Business Components

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 wizard to create a generic application for your ADF Mobile application.

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 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 a validator to the entity object.

Test the Application: Test the business logic in the Oracle Business Component Browser.

 

Install the Schema

tell me more icon 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...]





  1. go to OTN Download the schema zip file from OTN. If you created the schema previously, go to the cue cards icon next cue card.
  2. Unzip the file to a convenient location (for example, c:\temp).
  3. From the File menu, choose Open . Open the workspace c:\temp\Infrastructure\Infrastructure.jws.
  4. If you are prompted to migrate the project, click Yes to confirm.
  5. In the Application Navigator, expand the MasterBuildScript project and double-click build.properties to open it in the editor.
  6. 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
  7. In the MasterBuildScript project, select the build.xml file.
  8. In the Structure window, right-click the refreshSchema target and choose Run Target "refreshSchema."
  9. When prompted, enter the password for the database user with admin privileges.

    tell me more icon 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

tell me more icon 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...]





  1. Open the Create Application wizard [ File > New > General > Applications] .
  2. To follow along with the example, enter adfm as the short mobile application name using all lowercase letters.
  3. In the A pplication Package Prefix field, enter oracle.fod.mobile.
  4. Select Fusion Web Application (ADF) from the Applica tion Template list, then click Next .

    tell me more icon 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 in each project.   [ tell me more...]



  5. Change the project name to model (using all lowercase letters). Click Finish .
  6. In the Application Navigator, expand the Application Resources panel to see where resources for this application are displayed.

    tell me more icon In the IDE

    When you complete the steps for creating a new application and project, the Application Navigator should look like this, when the Projects and Application Resources panels are expanded:  [ tell me more...]



 

Create a Database Connection

tell me more icon 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...]





  1. Open the Create Database Connection dialog [ File > New > General > Connections > Database Connection] .
  2. Select Application Resources if it is not selected as the Create Connection In option.
  3. 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.
  4. Click Test Connection to confirm that you can connect.
  5. Click OK if the connection was successful.
  6. In the Application Navigator, expand the Connections and Database nodes in the Application Resources panel to see the database objects.

    tell me more icon In the IDE

    The database connection is now included as a resource for your application.   [ tell me more...]



 

Create Oracle ADF Business Components

tell me more icon Creating Oracle ADF Business Components

Oracle ADF Business Components is a model layer technology in the Oracle Application Development Framework (Oracle ADF). A fully-featured, XML-based framework for creating business services, ADF Business Components governs the interaction between the rest of the application and the data stored in the data source, providing validation, specific services, and other business logic.  [ tell me more...]





  1. 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] .
  2. In the Initialize Business Components Project dialog that opens before the wizard, confirm that the database connection you created (for example, FOD) is the current selection and click OK.
  3. On step 1 of the Business Components from Tables wizard, Entity Objects, click Query to populate the A vailable list.
  4. Select three tables, ORDERS, ORDER_ITEMS and PRODUCTS_BASE, from the A vailable list and shuttle icon shuttle them to the Selec ted list to create default business components based on them. Then click Next .
  5. On step 2, Updatable View Objects, select business components, Orders (FOD.ORDERS) and OrderItems (FOD.ORDER_ITEMS), from the A vailable list and shuttle icon shuttle them to the Selec ted list. Then click Next .
  6. Click Next to skip step 3, Read-Only View Objects, which aren't needed.
  7. On step 4, Application Module, change the application module name to FODModule. Then click Finish .

    tell me more icon Oracle ADF Business Components

    The Create Business Components from Tables wizard allows you to easily create a package of business domain components (entity objects, associations, and domains) from existing database objects and optionally to create a default package of data model components (view objects, view links, and an application module) from these newly generated business domain components.  [ tell me more...]



  8. Click save Save All to save your work.

    tell me more icon In the IDE

    After completing the Create Business Components from Tables wizard, the model project in the Application Navigator should look like this:  [ tell me more...]



 

Edit the View Object

tell me more icon 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...]





  1. In the Application Navigator, double-click OrdersView in the model project to open it in the view object editor.
  2. Select the Attributes tab to display all the attributes in the view object.
  3. Select the following attributes: PaymentOptionId, DiscountId, CouponId, CollectionWarehouseId, CreatedBy, CreationDate, LastUpdatedBy, LastUpdateDate, and ObjectVersionId. Then click delete icon Delete.

    tell me more icon 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...]



  4. In the Application Navigator, double-click OrderItemsView to open it in the view object editor.
  5. Select the Entity Objects tab.
  6. Select ProductsBase in the Available pane and shuttle icon shuttle it to the Selected pane.

    tell me more icon 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...]



  7. Select the Attributes tab. To add ProductsBase attributes to the OrderItemsView object, choose Add Attribute From Entity from the green plus icon Add dropdown menu.
  8. In the Attributes dialog, under the ProductsBase node in the A vailable pane, select ProductName and then shuttle icon shuttle it to the Selected pane. Then click OK.

    tell me more icon In the IDE

    The OrderItemsView view object now contains attributes from both the OrderItems entity object and the ProductsBase entity object. Notice that OrderItemsView 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

tell me more icon 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 the declarative validation capabilities in ADF Business Components, and define the logic using the Groovy scripting language.   [ tell me more...]





  1. In the Application Navigator, double-click Orders in the model project to open it in the entity object editor.
  2. Select the Business Rules tab, then select Entity Validators.
  3. Click add Add to open the Add Validation Rule dialog.
  4. Select Script Expression from the Rule Type dropdown list.
  5. On the Rule Definition tabbed page, enter OrderShippedDate == null || OrderShippedDate >= OrderDate in the E xpression pane. Click Test to verify the expression, and click OK when you see the expression syntax check message.
  6. Select the Failure Handling tab. Click add icon Add to add a row to the Message Text table.
  7. Double-click the default value below Message Id, then change the value to Orders_10.
  8. Change the default value below Message String to {0} cannot be earlier than {1}. Then press Enter or Tab.
  9. In the Token Message E xpressions table, 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.

    tell me more icon 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

tell me more icon Testing the Application in the Business Component Tester

You can test the validation rules you added, in the Oracle Business Component Browser. The browser 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...]





  1. In the Application Navigator, right-click FODModule and choose R un .
  2. In the Oracle Business Component Browser, double-click OrdersView1.
  3. 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.
  4. Click move to next row 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.
  5. 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.
  6. Click save changes to the database icon to save your changes, then close the Oracle Business Component Browser.
  7. Click save icon Save All to save your work.
  8. Close all the overview editors before continuing.

    tell me more icon In the IDE

    After entering a valid date and committing the change, the Oracle Business Component Browser shows the data that you have just saved to the database:   [ tell me more...]



 

cue cards iconNext step

 

Copyright © 1997, 2009, Oracle. All rights reserved.

false ,,,,,,,,,,,,,,,