Skip Headers

Oracle9i Lite Developer's Guide for Web-to-Go
Release 5.0.2
Part No. A97671-01
Go To Table Of Contents
Contents
Go To Index
Index

Previous Next

6
BC4J Tutorial

By using a sample application, this tutorial shows you how to create, deploy, and use a BC4J application.

The tutorial is organized according to the following topics:

6.1 Overview

Oracle's BC4J (Business Components for Java) is a part of Oracle9i JDeveloper's IDE (Integrated Development Environment), giving Java developers the tools to create and manage reusable Java components.

BC4J offers a standards-based, server-side Java and XML framework for developers who build and deploy reusable business components for high-performance Internet applications, such as e-commerce and business-to-business systems. Applications which are created by using BC4J comprise five basic framework components, namely, Entity Objects, Associations, View Objects, View Links, and Application Modules. Each of these components is interrelated to the other components, thereby enabling you to establish views into database tables. You can combine, filter, and sort data as needed.

When used in application development, BC4J automatically generates database-oriented components, enabling Web-To-Go developers to focus on the business logic instead of spending their time on database-related components during business application development.

The sample BC4J application which is used in this tutorial stores its items in a relational database. It maintains employee details.

6.1.1 Before You Start

Before you start developing business components in Java, you must ensure that the development computer meets the requirements specified below.

6.1.1.1 Development Computer Requirements

Table 6-1 lists configuration and installation requirements for the development computer.

Table 6-1 Development Computer Requirements

Requirement Description
Windows NT/2000/XP User Login The Windows NT/2000/XP login user must have Administrator privileges on the development computer
Installed Java Components Java Development Kit 1.3.1 or higher
Installed Oracle Components Mobile Server or Mobile Development Kit (Oracle9i Lite CD-ROM)

Oracle 8.1.7 or higher

Oracle9i JDeveloper, Release 9.0.3


Note:

The BC4J tutorial is shipped with the Mobile Development Kit as a JAR file named 9iLite_BC4J_Tutorial.jar. The file is located in the directory <Oracle_Home>\mobile\sdk\wtgsdk\src\. You can use this JAR file to publish the BC4J tutorial to the Mobile Server and then continue with the rest of the tutorial by following the steps in Section 6.7, "Deploying the Sample Application". If you want to develop the same application (as packaged in 9iLite_BC4J_Tutorial.jar), follow the steps from Section 6.2, "Developing the Application" to Section 6.6, "Running the BC4J Application on the Mobile Client for Web-To-Go" then continue to Section 6.7, "Deploying the Sample Application".

6.2 Developing the Application

This section enables you to develop the BC4J application for Oracle9i Lite in phases.

To develop the BC4J application, you must perform the following tasks.

  1. Create a database connection.

  2. Create the BC4J component.

  3. Configure the BC4J component to use the WTGJdbc connection.

  4. Build and deploy the BC4J component as a simple archive.

  5. Write the JSP application to access the BC4J component.

  6. Deploy the JSP application as a simple archive.

  7. Deploy the BC4J component into the Mobile Server.

6.2.1 Creating the Database Connection

To create the database connection, perform the following steps.

  1. In the Oracle9i JDeveloper project workspace, right-click on the "Connections" icon and click the "Connections" menu. The "Connection Manager Wizard" appears.

    Figure 6-1 displays the Connection Manager Wizard.

    Figure 6-1 Connection Manager Wizard

    Description of fig1_1.gif is contained in the surrounding text
  2. Click New. The Connection dialog box appears.

    Figure 6-2 displays the Connection dialog box which enables you to specify database connections for "tutorialConn" and "WTGJdbc".

    Figure 6-2 Connection Dialog Box

    Description of fig1_2.gif is contained in the surrounding text
  3. You must create two database connections: "tutorialConn" and "WTGJdbc" respectively. The "tutorialConn" connection connects to the primary Oracle database using "oracle.jdbc.driver.OracleDriver" for development and testing of the application. The "WTGJdbc" connection connects to the Oracle Lite database using "oracle.lite.web.WTGJdbcDriver". You can change the connection from "tutorialConn" to "WTGJdbc" before deploying the application as a simple archive. The "WTGJdbc" connection is used during application deployment and uses a different driver.

    To create a database connection for "tutorialConn", enter data in the Connections dialog box as specified in the following table.

    Table 6-2 lists values that you must specify for "tutorialConn" in the Connections dialog box.

    Table 6-2 tutorialConn Connection Requirements

    Field Values
    Connection Name tutorialConn
    Username scott
    Password tiger
    SID Your Database SID
  4. To create a database connection for "WTGJdbc", enter data in the Connections dialog box as specified in the following table.

    Table 6-3 lists values that you must specify for "WTGJdbc" in the Connections dialog box.

    Table 6-3 WTGJdbc Connection Requirements

    Field Values
    Connection Name WTGJdbc
    Select a JDBC Driver Other JDBC
    Class Name oracle.lite.web.WTGJdbcDriver
    Datasource URL jdbc:oracle:webtogo

    Note:

    In the Connection dialog box, you must enter values for fields only as specified in Table 1-2 and Table 1-3. Retain all other values as default values.

  5. Click "Test Connection" to test the "tutorialConn" database connection. The system displays a message stating that the database connection is successful.

  6. Click "OK". The database connection is now created.

6.2.2 Creating the BC4J Component

Using Oracle9i JDeveloper, you can create the BC4J component named "tutorialapp".

To create the BC4J component named "tutorialapp", perform the following steps.

  1. In Oracle9i JDeveloper, select New from the File menu. In the New dialog box that appears, "Projects" in the left panel and "Empty Project" in the right panel are pre-selected as the defaults. Click OK. Oracle9i JDeveloper creates a new empty project named "Project.jpr".

  2. Rename "Project.jpr" to "tutorialapp.jpr", which creates a new project by that name.

  3. Right click "tutorialapp.jpr" in the Oracle9i JDeveloper workspace. Select the "New Business Components Package..." The "Business Components Package Wizard, Welcome" dialog box appears. Click Next.

    Figure 6-3 displays the "Business Components Package Wizard, Welcome" dialog box.

    Figure 6-3 The Business Components Package Wizard, Welcome Dialog Box

    Description of fig1_3.gif is contained in the surrounding text
  4. The "Business Components Package Wizard, Step 1 of 3: Package Name" dialog box appears, as illustrated in Figure 6-4. In the Package Name field, enter tutapp. Then, click Next.

    Figure 6-4 Business Components Package Wizard, Step 1 of 3: Package Name

    Description of fig1_4a.gif is contained in the surrounding text
  5. The "Business Components Package Wizard, Step 2 of 3: Connection" dialog box appears, as depicted in Figure 6-5. Select the values that are listed in Table 6-4 and click Next.

    Figure 6-5 Business Components Package Wizard, Step 2 of 3: Connection

    Description of fig_5b.gif is contained in the surrounding text

    Table 6-4 Values for Business Components Package Wizard, Step 2 of 3: Connection

    Field Description
    Connection Name tutorialConn
    SQL Flavor SQL92
    Type Map Oracle
  6. In the "Business Components Project Wizard, Step 3 of 3: Business Components" dialog box, select "EMP" from the list displayed in the left panel and move it to the "Selected" list, as illustrated by the example in Figure 6-6. Click "Finish".

    Figure 6-6 Business Components Package Wizard, Step 3 of 3: Business Components Dialog Box

    Description of fig_5a.gif is contained in the surrounding text
  7. At this stage, Oracle9i JDeveloper creates the BC4J component named "tutorialapp".

6.2.3 Configuring the BC4J Component to Use the WTGJdbc Connection

To configure the BC4J component to use the WTGJdbc connection, perform the following steps.

  1. Right-click on the "TutorialappModule" and double-click on the "Configurations..." option. The Configuration Manager appears.

  2. In the Oracle Business Component Configuration dialog box, click "Edit". Choose "WTGJdbc" as the JDBC connection.

  3. Click "OK". The BC4J component is now configured to use the WTGJdbc connection.

6.2.4 Building and Deploying the BC4J Component as a Simple Archive

To build and deploy the BC4J component as a simple archive, perform the following steps.

  1. Right-click the "tutorialapp.jpr" file and select the "Create Business Components Deployment Profiles" option. The Deployment Wizard appears.

  2. Select the "Simple Archive Files" option from the list displayed and move it to the "Selected" list.

  3. Under the Selected platform - Simple Archive Files section, select the "Deploy" check box.

  4. Click "OK". The system creates two "jar" files namely "tutorialapp.jar" and "tutorialappCommonCS.jar".

6.2.5 Writing the JSP Application to Access the BC4J Component

To write the JSP application that will access the BC4J component, perform the following steps.

  1. In Oracle9i JDeveloper, select the "Empty Project" option under the File menu. The system automatically creates a new empty project called "MyProject.jpr".

  2. Under the File menu, select the "Rename..." option and rename "MyProject.jpr" to "tutorialclientapp.jpr".

  3. Click the "tutorialclientapp.jpr" file in the Oracle9i JDeveloper workspace. Click the File menu and select "New". Click the "Web Tier" option and select "Business Components JSP Application". Click OK. The "Business Components JSP Application Wizard" appears.

  4. Click "New...". The "BC4J Client Data Model Definition Wizard" appears. Click Next. The "BC4J Client Data Model Definition Wizard: Step 1 of 2: Definition" appears, as illustrated in Figure 6-7.

    Figure 6-7 BC4J Client Data Model Definition Wizard, Step 1 of 2: Definition

    Description of def_1.gif is contained in the surrounding text
  5. Verify the default selected values and click Next. "TutappModule" appears as the default Definition Name in the "BC4J Client Data Model Definition Wizard - Step 2 of 2: Definition Name" dialog box. Click Next.

  6. Click Finish. The "Business Components JSP Application Wizard" dialog box appears. Click Next.

  7. In the "Business Components JSP Application Wizard - Step 1 of 3: Data Definition" dialog box, select "TutappModule" as the data model definition, as illustrated in Figure 6-8. Click Next.

    Figure 6-8 Business Components JSP Application Wizard - Step 1 of 3: Data Definition

    Description of def_2.gif is contained in the surrounding text
  8. Accept the default selections and click Next in the two dialog boxes that appear: "Business Components JSP Application Wizard - Step 2 of 3: View Object Forms" and "Business Components JSP Application Wizard - Step 3 of 3: View Link Form". Click Finish when the Summary window appears.

6.2.6 Deploying the JSP Application as a Simple Archive

To deploy the JSP application as a simple archive, perform the following steps.

  1. In Oracle9i JDeveloper, click the tutorialclientapp.jpr file and select the tutappclient_jpr_war.deploy file.

  2. Select "Deploy to WAR file". The file tutappclient_jpr_war.war gets created. To get the deployed location, check the "Deployment Log" text area in Oracle9i JDeveloper.

6.3 Packaging the JSP Application

To package the JSP application, perform the following steps.

  1. Create a sub-directory called "bc4jtutapp" under the following location: &fmv435;\Mobile\Sdk\wtgsdk\root

  2. Unzip the tutappclient_jpr_war.war file into the "bc4jtutapp" directory.

  3. Edit all of the JSP files to delete the following:

    ;charset=windows-1252
    
    

    from

    <%@page language="Java"errorpage="errorpage.jsp" ContentType="text/html;charset=windows-1252"%>
    
    
  4. Edit Emp.xml and change:

    DBObjectName="SCOTT.EMP"
    
    

    to the following:

    DBObjectName="EMP"
    
    
  5. Edit EmpView.xml and change:

    LIST="SCOTT.EMP"
    
    

    to the following:

    LIST="EMP Emp"
    
    
  6. Using the Command Prompt window, run the Packaging Wizard and provide the screen inputs that are listed and described in Table 6-5.

    Table 6-5 Packaging Wizard Input Details

    Screen Input Details
    Platform Web-To-Go NA
    Application Application Name BC4J 9iLite Tutorial Application
    Application Virtual Path /bc4jtutorial
    Application Description BC4J 9iLite Tutorial Application
    Application Application Classpath no input
    Application Default Page main.html
    Application Local Application Directory &fmv436;\Mobile\Sdk\wtgsdk\root\bc4jtutapp
    Files The Packaging Wizard loads all files in a directory under the Local Application Directory. NA

    Table 6-6 lists the servlet names and their corresponding classes that are created in the Packaging Wizard by default.

    Table 6-6 Servlet Names and Classes

    Screen Servlet Name Servlet Class
    Servlet EMDServlet oracle.jbo.server.emd.EMDServlet
    Servlet ImageServlet oracle.cabo.image.servlet.ImageServlet
    Servlet TecateServlet oracle.cabo.image.servlet.TecateServlet
    Servlet BajaServlet oracle.cabo.servlet.BajaServlet
    Servlet OrdPlayMediaServlet oracle.ord.html.OrdPlayMediaServlet

    Table 6-7 lists Server side and Client side Database values that you must specify in the Packaging Wizard.

    Table 6-7 Database Values

    Screen Input Details
    Database Server side Database User Name scott
    Database Number of Connections 0
    Database Share Connections Do not select this check box
    Database Client side Database Name Client DB
  7. Under the Snapshots section, click "Import...". You can now connect to the Oracle Database by providing the following values in the "Connect to Database" dialog box.

    Table 6-8 lists values that you must specify in the Connect to Database dialog box.

    Table 6-8 Connect to Database Window Description

    Field Description
    Username scott
    Password tiger
    Database URL jdbc:oracle:oci8:@webtogo.world
  8. After specifying the Database Connection values, select "Emp" from the list of tables.

  9. Click "Edit" and change the weight to "1" from "0".

  10. You must retain the default values for Roles, Sequences, DDLs, and Registry fields.

  11. Package the application into a JAR file.

6.4 Publishing and Configuring the JSP Application from the Control Center

To configure the JSP application from the Control Center, perform the following steps.

  1. Using the Command Prompt window, enter "webtogo-d0" to start the Mobile Server.

  2. Using the following URL, browse the local host:

    http://localhost

  3. Login into the Mobile Server using the administrator username and password.

  4. Click "Control Center".

  5. Click the "Application" tab and then publish the JAR file you created.

  6. Click the "Users" tab, and create a new user called "tutorial". Enter "tutorial" as the password. Assign "Users" as the privilege for the new user.

  7. Click the "Applications" tab.

  8. Click the "BC4J 9iLite Tutorial Application" link.

  9. Click "Properties".

  10. Under the "Database Connectivity" section, in the "Database Password" field, enter "tiger".

  11. Click "Access" to provide user access to the "BC4J 9iLite Tutorial Application".

6.5 Testing the BC4J Application

To test the BC4J application, login to the Mobile Server as a "tutorial" user. In the "tutorial" workspace, double-click the "BC4J 9iLite Tutorial Application". The Business Components JSP Application window appears. Click "EmpView" and browse through the employee table records.

6.6 Running the BC4J Application on the Mobile Client for Web-To-Go

To run the BC4J application on the Mobile Client for Web-To-Go, perform the following steps.

  1. Using the following URL, check the Database Server's IP address setup:

    http://server_ip_address/setup

  2. Download and install the Mobile client for Web-To-Go with BC4J support.

  3. Using the following URL, check the local host in the client machine:

    http://localhost in client machine

  4. Log in to the client machine using "tutorial" as the username and password.

  5. After the client machine synchronizes the application and data from the server, click the "BC4J 9iLite Tutorial Application" link to test the application on the client machine.

6.7 Deploying the Sample Application

To deploy the sample application, perform the following steps.

  1. Log in to the database as a system user. Run the "bc4j.sql" script if the SCOTT schema does not exist already.

  2. Publish the 9iLite_BC4J_Tutorial.jar file, which is found under
    <Oracle_Home>\Mobile\Sdk\wtgsdk\src\bc4jtutorial>,
    into the Mobile Server by using the Control Center and entering the following virtual path:

    /bc4jtutorial

  3. Click "Control Center" and choose the "Applications" tab.

  4. Click the "9iLite BC4J Application".

  5. Choose the "Properties" link, and enter "tiger" as the database password. Click Save.

  6. Create a user called "tutorial" with "user" as the privilege, in case the user "tutorial" doesn't exist already.

  7. Provide user access to the user named "tutorial" to the "9iLite BC4J Application".

  8. Using the following URL, browse the client machine with BC4J support.

    http://servername:port/webtogo/setup

  9. Download and install the Web-To-Go Mobile client.

  10. Start the Web-To-Go client if it is not started already.

  11. Log in to the Web-To-Client with "tutorial" as the username and password.

  12. Upon completion of the Synchronization process, the system displays the "9iLite BC4J Application" link.

  13. Click the "9iLite BC4J Application" link to access the BC4J tutorial application.


Previous Next
Oracle Logo
Copyright © 2002 Oracle Corporation

All rights reserved
Go To Table Of Contents
Contents
Go To Index
Index