Tutorial - Building BC4J

This tutorial walks you through the steps of building a simple Business Components application based on the DEPT and EMP tables in the SCOTT schema and creating a JSP client for the application.

Note: This tutorial requires Business Components Editor, which you can download for free from the Oracle Technology Network at http://otn.oracle.com/products/bc4j/. To gain access to this free resource, go to OTN's registration page.

This tutorial is organized by the following tasks:

  1. Creating a Business Components Project
  2. Creating a Default Application
  3. Generating the Makefile
  4. Writing a JSP Client
  5. Deploying the JSP Client and Business Components
  6. Running the JSP Client

Requirements:

To work through this tutorial, you need the following:

This tutorial should take you about an hour to complete.

Creating a Business Components Project

Putting all your Business Component files into one project makes browsing packages easier and simplifies deployment.

To create a new project:

  1. In the menu for the Business Component Editor, choose File | New to create a new project.
  2. In the Project dialog box, change the Project name to DeptToEmpProject.
  3. Name the project's default Package name deptToEmp.
  4. Click OK.
  5. The Business Components Project Wizard opens.

Creating a Default Application

When you create a new Business Components Project, the Business Components Project Wizard starts automatically. You can use this wizard to create default (generic) Business Components which you can modify later.

To create a default application using the Business Components Project wizard:

  1. When the wizard opens, if the Welcome page appears, review the information there and click Next.
  2. In the Connection page, establish a JDBC connection to your database. If no connections are listed, click Add to create a new connection. The Connection dialog box will appear.
    1. In the Connection Name field, enter BCED_jdbc.
    2. In the Username and Password fields, enter scott and tiger, respectively. Leave the Role field Normal.
    3. Select Include password in deployment archive. By storing the password in the deployment archive, you won't have to enter the password every time you connect.
    4. In the Host Id field, enter the name of the database you want to connect to. Fill in the appropriate SID and Port for this connection. If you do not know these values, check with your database administrator.
    5. Click Test Connection. A dialog box will open to indicate the status. When the dialog box closes, you should see the message "Connection succeeded" next to the Test Connection button. If an error occurs, verify your settings with your database administrator.
    6. Click OK to close the Connection dialog box.
  3. On the Connection page of the wizard, click Next.
  4. In the Package Name page, accept the default package name (deptToEmp) and click Next.
  5. In the Business Components page, select the tables you will use to create Entity Objects.
    1. From the Database Schema list, select SCOTT. (If not already selected, select the Tables checkbox.)
    2. In the Available list, control-click to select Dept and Emp, and click the right-arrow (>) button to shuttle the selected tables to the Selected list. Default Entity Objects and Associations will be created for these database objects.
    3. Make sure the View Objects and View Links checkbox is selected. This will generate default View Objects and View Links based on the selected Entity Objects.
    4. Make sure the Application Module checkbox is selected. This will create a default Application Module which you can modify later.
    5. Click Next.
  6. On the Finish page, click Finish to generate the application. In the Navigation pane of the Business Component Editor, notice the Business Components that have been added to your project.

To recap these steps, you did the following:

Generating the Makefile

The Business Component Editor allows you to create, test, and modify your middle tier locally, and then deploy it with very few changes. Before you can test the application locally, you need to generate and run the makefile.

To generate the makefile:

  1. In the Navigation pane of the Business Components Editor, click DeptToEmpProject to make it the active node, and select Object | Generate Makefile.
  2. When the Generate Makefile dialog box opens, click OK. (To run the Business Component Browser in local mode you do not need to specify a deployment target.)

To run the makefile on Unix:

  1. Open a command prompt.
  2. Navigate to your [BCED_Home]/myprojects directory.
  3. Run make on the project file.

    make -f DeptToEmpProject.mkx

To run the makefile on Windows NT:

  1. Open a command prompt.
  2. Navigate to your [BCED_Home]\myprojects directory.
  3. Run nmake on the project file.

    nmake /f DeptToEmpProject.mak

When you finish running the makefile, go back to the Business Component Editor. Don't close the terminal (DOS window) yet, you will use it again later.

Writing a JSP Client

Here you will build a JavaServer Page(JSP) HTML front-end for the application. This is a very simple JSP which gives you a view of the EmpView View Object.

This JSP requires the oracle.css stylesheet and two Web Beans. The cascading style sheet (CSS) facilitates the presentation of the JSP, and while you could code the Web Beans by hand, they are included in the BCED distribution for ease of use.

To create a JSP client:

  1. Create a blank HTML document.
  2. At the top of the page, enter the following import statement:

    <%@ import = "java.util.*, oracle.jbo.*, oracle.jbo.common.ampool.*" %>

  3. To facilitate presentation, you will use a style sheet. Between the <head> tags, add the following to use the Oracle stylesheet:

    <LINK REL=STYLESHEET TYPE="text/css" HREF="/webapp/css/oracle.css">

  4. The first Web Bean you will add is a navigation bar. Add the following lines in the body of the page:

    <jsp:useBean class="oracle.jbo.html.databeans.NavigatorBar" id="NavBar" scope="request" >
    <%
    NavBar.setTargetUrl("EmpView.jsp");
    NavBar.initialize(application, session, request, response, out,

    "deptToEmp_DeptToEmpModule.EmpView");
    NavBar.render();
    %>
    </jsp:useBean>

  5. The next Web Bean you will add is for viewing records. Add a line break <br> and then add the following code:

    <jsp:useBean class="oracle.jbo.html.databeans.ViewCurrentRecord" id="RowViewer" scope="request">
    <%
    RowViewer.initialize(application, session , request, response, out, "deptToEmp_DeptToEmpModule.EmpView");
    RowViewer.setReleaseApplicationResources(true);
    RowViewer.render();
    %>
    </jsp:useBean>

  6. Save the file as SampleJSPClient.jsp.

Deploying the JSP and Business Components

To deploy the JSP you need to copy your JSP file, your business components, and the web beans and CSS file used by your JSP to Oracle 9iAS, and add the web beans and business components to the classpath.

To deploy the JSP:

  1. Copy your JSP file to [9iASHome]/Apache/Apache/htdocs.
  2. Copy the oracle.css file to [9iASHome]/Apache/Apache/htdocs. This file is located in [BCED_Home]/doc/wh/oracle/Tutorials/webapp.zip.
  3. Copy [BCED_Home]/doc/wh/oracle/Tutorials/webapp.zip to [9iASHome]/Apache/BC4j/lib.
  4. Copy
  5. [BCED_Home]/myclasses/DeptToEmpProject.jar to [9iASHome]/Apache/BC4j/lib.
  6. Open the file /Apache/Jserv/etc/jserv.properties in a text editor.
  7. Find the block that begins with the comment

    # OJSP environment settings
  8. Add the following lines to the end of the block:

    wrapper.classpath=[IAS_Home]/Apache/BC4J/lib/webapp.zip
    wrapper.classpath=[IAS_Home]/Apache/BC4J/lib/DeptToEmpProject.jar

Running the JSP Client

Note: To run the JSP you must use http:// not file://.

To run the JSP client:

  1. Restart Oracle9iAS.
  2. In a web browser, navigate to your Oracle9iAS server.
  3. Open SampleJSPClient.jsp.