Legal | Privacy
Developing an End-to-End Web Application Using the Default Technology Scope

Developing an End-to-End Web Application Using the Default Technology Scope

This lesson teaches you how to develop a web application using JSP pages, Struts, and Oracle ADF business components.

Topics

This lesson will discuss the following:

Overview
Prerequisites
Step 1 - Create the Business Services

Step 2 - Create a JSP for Browsing data

Step 3 - Create a JSP for Creating data
Step 4 - Create a JSP for Editing data

Step 5 - Deploying the Application

Summary

This lesson should take about an hour to complete.

Move your mouse over this icon to show all screenshots. You can also move your mouse over each individual icon to see only the screenshot associated with it.


Overview

This lesson teaches you how to use JDeveloper to develop a web-based application that implements the design patterns pioneered by Sun Microsystems, a set of best practices for developing J2EE applications. In this lesson, you'll create the application using JavaServer Pages, Struts, and Oracle ADF Business Components. ADF Business Components automatically implement the J2EE design patterns and provide a more productive framework-based development environment than plain EJBs.

Back to Topic List

Before starting to develop an application, you need to select the technology scope for your development environment, or workspace. For this application, you'll set your workspace to use the web application template. The web application template implements the MVC design pattern by creating two projects within your workspace; a project containing the view and controller, and a project containing the model. There are two web application templates; you will choose the default technology scope. This sets your project to use JSP, Struts, and ADF Business Components.

The following graphic shows how your project will be organized. Notice that the ViewController project contains the view and controller portions of your application, while the Model project contains the business services. You will build your application from the bottom up: that is, first you'll create your persistent business objects (ADF entity objects), next you'll create your data access objects (ADF view objects), and so on.


Prerequisites

Back to Topic List

Before starting this lesson, you should have completed the following:

1.

Install Oracle JDeveloper 10g.

 

2.

Install the sample schema and create a connection to the HR or HR8 schema to use in this lesson. See Installing the Sample Schemas and Establishing a Database Connection.

 

 

Step 1 - Create the Business Services

Back to Topic List

To create business services, follow these steps:

Create a New Application Workspace
Create a Business Components Diagram
Create Entity Objects

Create View Objects

Create Business Services in an Application Module

Create a New Application Workspace

Back to List

1.

In the Application Navigator, right-click the Applications node and click New Application Workspace...

Move your mouse over this icon to see the image

The Create Application Workspace dialog opens.

 

2.

Change the Application Name to HumanResourcesApp.
In the Application Templates field, choose Web Application [Default] from the dropdown list.
There are several application templates available from the dropdown list. Each one can be custom tailored to add (or delete) technologies of your choice by choosing Edit Templates.

Move your mouse over this icon to see the image

Click OK. Your new application is represented in the Application Navigator by two new projects, Model and ViewController.

 

3.

From the File menu, choose Save All.

 

 

Create a Business Components Diagram

Back to List

In this step you'll create a new business components diagram for your business tier objects. Diagrams give you a visual representation of your business objects, helping you conceptualize and organize your application.

1.

In the Application Navigator, right-click Model and choose New.

Move your mouse over this icon to see the image

The New Gallery opens. Notice that the New Gallery is tailored to show only those technologies that are applicable to the Model project.

 

2.

In the New Gallery, under the Categories list, select Business Components, and then in the Items list, select Business Components Diagram.

Move your mouse over this icon to see the image

Click OK. The Create Business Components Diagram dialog opens.

 

3.

Change the name of the diagram to Business Components HR Diagram and accept the default package name.

Move your mouse over this icon to see the image

Click OK. Your new business components diagram appears as an empty page in the IDE. Since you don't have any objects on the diagram, the thumbnail view and Structure pane are blank.

 

4.

From the File menu, choose Save All.

 

 

Create Entity Objects

Back to List

In this technology scope, your persistent business objects are ADF entity objects. Entity objects implement the Data Access Object design pattern, and are responsible for persisting and caching data, and also for validation. You can create entity objects by dragging them from a database table and dropping them onto a business components diagram.

1.

In the Navigator, click the Connections tab.

Move your mouse over this icon to see the image

 

2.

In the Connection Navigator, expand the nodes for Database and tutorial_jdbc_connection.

If you have not established this connection to the HR schema, please see the prerequisites section above.


Move your mouse over this icon to see the image

 

3.

In the Connection Navigator, expand the nodes for HR and Tables. Click DEPARTMENTS then drag and drop it onto the blank diagram.

Move your mouse over this icon to see the image


The Create from Tables dialog opens.

 

4.

In the Create from Tables dialog, make sure that Business Components Entity Objects is selected and click OK.

Move your mouse over this icon to see the image

The Departments object is added to the diagram.

 

5.

In the Navigator, click the Applications tab to bring the Application Navigator to the front. Notice that the Departments entity object appears in the model package.

 

6.

From the File menu, choose Save All.

 

 

Create View Objects

Back to List

The entity object you created in the previous step is used for persisting and caching data about departments, and for encapsulating business rules. The next object you'll create is an object for gathering and filtering data stored in your entity object. The ADF business component responsible for this is the view object. View objects use a SQL query to form a collection of data.

1.

On the Component Palette, select View Object, and then click on an empty space in the business components diagram to create a new view object.

Move your mouse over this icon to see the image

A new view object appears on the diagram.

 

2.

Change the view object's name to DepartmentsView.


Move your mouse over this icon to see the image

 

3.

On the diagram, click the Departments entity object and drag it inside the border of DepartmentsView.

Move your mouse over this icon to see the image

Your view object now contains attributes that map 1:1 to the Departments entity object.

 

 

Creating Business Services in an Application Module

Back to List

An ADF application module is a service object that coordinates view objects for a specific task. For example, in this application your application module will display the department's ID number, name, location, and manager ID. An application module is usually task-specific, containing only the business services required for the application at hand. If you are used to a form-based development environment, an application module usually exists for each form. In this step you'll create an application module that contains the view object you created on the business components diagram.

1.

1. On the Component Palette, select Application Module and click on the diagram to create a new application module.

Move your mouse over this icon to see the image

A new application module appears on the diagram.

 

2.

Change the name to DepartmentsModule.


Move your mouse over this icon to see the image

 

3.

On the diagram, click the DepartmentsView view object and drag it inside the border of DepartmentsModule.

Move your mouse over this icon to see the image

The business services portion of your application is now complete: it contains a persistent business object for caching data and encapsulating business rules (an entity object), a data access object for gathering and filtering data (a view object), and a business service object that exposes the services of your application (application module).

 

Step 2 - Create a JSP for Browsing Data

Back to Topic List

In this step you'll start working on the controller and view parts of your MVC application. The controller separates the visual representation of web pages from their flow and actions. You will create a page flow diagram, which visually organizes the flow and actions of your web pages, and add a JSP for viewing Department data. Note that this lesson covers the use of JSPs for the view component, but you could also use UIX or JClient technologies to create the view. See the related topics section for further information on creating UIX pages.

1.

In the Application Navigator, expand the ViewController project, the Web Content folder, and the WEB-INF folder. Double-click struts-config.xml and you'll see a blank page flow diagram.

Move your mouse over this icon to see the image

 

2.

Oracle ADF provides a data action (oracle.adf.controller.struts.actions.DataAction)
to prepare the binding context for databound web pages and to execute custom business
service methods exposed through the model. A data page is a combination of a data action, forward, and web page. The behavior of the data action subclass (dataForwardAction) is identical to the data action;
however, the Page Flow Modeler simplifies the combination of objects to show a single element.


In the Component Palette, click the Data Page element and then click on the diagram to create the data page.

Move your mouse over this icon to see the image

A new data page appears on the diagram.

 

3.

Change the name to /browseDepartments.

Move your mouse over this icon to see the image

 

4.

Double-click /browseDepartments to create the JSP. Accept the default JSP name and click OK to open it in the visual JSP editor.
Optionally, add the text List of Departments to the JSP. Add a style sheet and modify the JSP page as needed.

Move your mouse over this icon to see the image

 

5.

On the Component Palette, click the Data Controls tab. On the Data Control Palette, click DepartmentsView1. In the Drag and Drop As dropdown list, select Read-Only Table.

Move your mouse over this icon to see the image

 

6.

Drag DepartmentsView1 from the list of Business Services and drop it onto browseDepartments.jsp in the Editor.

Move your mouse over this icon to see the image


A new table is created on the page. Right now, the table is functional, but it would only show the first 10 records in the Departments table because the default iterator size is 10.

 

7.

In the Data Control Palette, expand the nodes for DepartmentsView1 and Operations, and click First.
In the Drag and Drop As dropdown list, select Button with Form.

Move your mouse over this icon to see the image

 

8.

Drag and drop the operation onto browseDepartments.jsp to create the button.

Move your mouse over this icon to see the image

 

9.

In a similar manner, drop Previous, Next, and Last buttons from the Data Control palette to browseDepartments.jsp. Select Button from the Drag and Drop As dropdown list to create the buttons in the same form as the First button.

Move your mouse over this icon to see the image

Drag the buttons around if you want to arrange them differently.

 

10.

From the File menu, choose Save All.

 

11.

In the Page Flow Diagram, right-click /browseDepartments.jsp and select Run.

Move your mouse over this icon to see the image

Navigate through the records using the navigation buttons.

 

 

Step 3 - Create a JSP for Creating data

In this step you'll create a JSP page that binds to a business service method that inserts a new row. You will then edit the JSP to allow the user to create new department data.

 

1.

Now create a page flow for inserting new department data. In the Component Palette, click the Data Page element and then click on the diagram to create it. Change the name to /createDepartments.

Move your mouse over this icon to see the image

 

2.

Choose the Forward component in the Component Palette, click on /browseDepartments, drag the forward component to the /createDepartments Data Page, and click again.

Move your mouse over this icon to see the image

 

3.

Click on the forward name success and in the Property Inspector, change the name attribute to Create.

Move your mouse over this icon to see the image

 

4.

Choose the Forward component in the Component Palette, click on /createDepartments, drag the forward component to the /browseDepartments Data Page, and click again. Rename the forward Submit.

Move your mouse over this icon to see the image

5.

Double-click /createDepartments to create the page. Accept the default name, and click OK to open it in the visual JSP editor.
Optionally, add the text Insert a New Department to the JSP. Add a style sheet and modify the JSP page as needed.

Move your mouse over this icon to see the image

 

6.

On the Data Control Palette, click DepartmentsView1. In the Drag and Drop As dropdown list, select Input Form.

Move your mouse over this icon to see the image

 

7.

Drag DepartmentsView1 from the Data Control Palette and drop it onto createDepartments.jsp in the Editor.

Move your mouse over this icon to see the image


A new insert form is created on the page.

 

8.

To create and commit the inserted row, add buttons to browseDepartments.jsp. In the Application Navigator, double-click browseDepartments.jsp to open it in the visual editor.
In the Data Control Palette, expand the Operations node and click Commit.

Move your mouse over this icon to see the image

 

9.

Drag the Commit button onto browseDepartments.jsp, just below the navigation buttons.

Move your mouse over this icon to see the image

 

10.

In the Data Control Palette, select the Rollback button and drag it onto browseDepartments.jsp.

Move your mouse over this icon to see the image

 

11.

Now create a button to invoke createDepartments.jsp from browseDepartments.jsp. In the Data Control Palette, select Create and in the Drag and Drop As dropdown list, select Button with Form. Drop the operation onto browseDepartments.jsp, below the navigation and transaction buttons form.

Move your mouse over this icon to see the image

 

12.

Click on the Create button and in the Property Inspector, change the value attribute to Insert a New Department.

Move your mouse over this icon to see the image

 

13.

From the File menu, choose Save All.

 

14.

In the Page Flow Diagram, right-click /browseDepartments.jsp and select Run.
Click Insert a New Department.

Move your mouse over this icon to see the image

You will be forwarded to the insert form.

 

15.

Create a new department record and click Submit.

Move your mouse over this icon to see the image

You will be forwarded to the Browse form.

 

16.

Click Commit in browseDepartments.jsp to commit the new record.

Move your mouse over this icon to see the image

 

Step 4 - Create a JSP for Editing Data

Back to Topic List

In this step you create a data action and data page for editing department data. You will link to the edit form via the browse form.

1.

Now create a Data Page to select the current row for editing. Open the Struts Page Flow Diagram and in the Component Palette, click Data Page.

Move your mouse over this icon to see the image

 

2.

Click on the page flow diagram to create the Data Page and rename it /editDepartments.

Move your mouse over this icon to see the image

 

3.

Choose the Forward component in the Component Palette, click on /browseDepartments, drag the forward component to the /editDepartments Data Page, and click again.

Move your mouse over this icon to see the image

 

4.

Rename the forward setCurrentRowWithKey.

Move your mouse over this icon to see the image

 

5.

Choose the Forward component in the Component Palette, click on /editDepartments, drag the forward component to the browseDepartments Data Page, and click again. Rename the forward Submit.

Move your mouse over this icon to see the image

 

6.

Double-click browseDepartments.jsp to open it in the editor.
In the Data Control Palette, select setCurrentRowWithKey(String) from the operations node of DepartmentsView1.
In the Drag and Drop As dropdown list, select Find Row Link.

Move your mouse over this icon to see the image

 

7.

Drag the Find Row Link from the Data Control Palette onto the browseDepartments.jsp page, just in front of the Row.DepartmentId field and change the text of the link to Edit.

Move your mouse over this icon to see the image

 

8.

In the page flow diagram, double-click /editDepartments to create the corresponding JSP page. Accept the default name and click OK to open it in the editor.
Optionally, add Edit Department Information to the JSP. Add a style sheet and modify the JSP page as needed.

Move your mouse over this icon to see the image

 

9.

In the Data Control Palette, select DepartmentsView1.
In the Drag and Drop As dropdown list, select Input Form.

Move your mouse over this icon to see the image

 

10.

Drag the Input Form from the Data Control Palette onto the editDepartments.jsp page.

Move your mouse over this icon to see the image

 

11.

From the File menu, choose Save All.

 

12.

From the Page Flow Diagram, right-click /browseDepartments and select Run. In the browser, click on the Editt link next to any Department id.

Move your mouse over this icon to see the image

You will be forwarded to the Edit form.

 

13.

Edit the Department information and click Submit.

Move your mouse over this icon to see the image

You will be forwarded to the Browse form.

 

14.

Press Commit in browseDepartments.jsp to commit the change.

Move your mouse over this icon to see the image

 

 

Step 5 - Deploying the Application

Back to Topic List

The last step in developing an application is deploying it. Follow these steps to deploy the application to Oracle Containers for J2EE (OC4J) .

1.

Ensure your PATH environment variable includes the jdk\bin directory within the JDeveloper root directory. Open a DOS window and navigate to the J2EE/home directory inside the JDeveloper root directory.

Move your mouse over this icon to see the image

 

2.

Issue java -jar oc4j.jar -install at the prompt. Specify welcome as the admin password.

Move your mouse over this icon to see the image

 

3.

Issue java -jar oc4j.jar to start the OC4J server.

Move your mouse over this icon to see the image

 

4.

In JDeveloper, click the Connections tab in the System Navigator.
Right-click Application Server and choose New Application Server Connection.

Move your mouse over this icon to see the image

The Create Application Server Connection dialog opens.
Click Next.

 

5.

In the Create Application Server Connection dialog, name the connection OC4J.
Choose Standalone OC4J from the Connection type dropdown list.

Move your mouse over this icon to see the image

Click Next.

 

6.

Enter the username and password that you entered when you installed OC4J.

Move your mouse over this icon to see the image

Click Next.

 

7.

Ensure the ORMI hostname is correct, and accept the default target web site and location of OC4J.

Move your mouse over this icon to see the image

Click Next.

 

8.

Click Test Connection. JDeveloper will attempt to connect to the OC4J server. When the process is complete and the status is "Success!", click Finish.

Move your mouse over this icon to see the image

 

9.

In the System Navigator, click the Applications tab.
Right-click ViewController and choose New...

Move your mouse over this icon to see the image

The New Gallery opens.

 

10.

Expand the General category and choose Deployment Profiles.
Select WAR file from the items list.

Move your mouse over this icon to see the image

Click OK.

 

11.

Name the Deployment Profile HRApplication and accept the default directory.

Move your mouse over this icon to see the image

Click OK to open the WAR Deployment Profile Properties dialog.
Accept the default properties and click OK to create the deployment profile.

 

12.

In the Application Navigator, right-click HRApplication.deploy.
Select Deploy To -> OC4J.

Move your mouse over this icon to see the image

The application WAR file will be deployed to OC4J. Wait for the text Deployment Finished in the Message log.

 

13.

In the Deployment messages, copy the text on the line following: Use the following context root(s) to test your web application(s)

 

14.

Paste the url into a browser. Append a forward slash, and add /browseDepartments.do to the end of the url. Press enter to run the application.

 

Back to Topic List

In this lesson you learned how to use JDeveloper to develop and deploy a web-based application that implements the MVC design pattern, using JSPs, Struts, ADF Business Components, and the data binding features of the Oracle Application Development Framework (Oracle ADF).

Installing the Sample Schemas and Establishing a Database Connection

Developing Applications with Oracle ADF UIX

Instructor-led course entitled, "Oracle JDeveloper 10g: Build Applications with Oracle ADF" (available March 2004)

Move your mouse over this icon to hide all screenshots

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy