Creating a JSP Application with ADF Using a Model 1 Architecture
Creating a JSP Application with ADF Using a Model 1 Architecture
Purpose
This tutorial shows you how to create databound JSP pages in
a Model 1 environment. Model 1 is a specific use of the MVC pattern where controller
and view are tightly coded together inside JSPs. This usage of MVC is JSP-centric
with logic for event handling and flow control inside the JSP itself.
The focus of this lesson is how the view and controller
elements are built. But since a valid business model is required for our example, we have
chosen to use ADF Business Components because it provides the easiest way of establishing
the business services for this lesson.
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
The goal of this tutorial is to teach you how to build a JSP application
with JDeveloper using a Model 1 environment.
The JSP application that you create in this tutorial will display
departments and employees information based on the "Human Resources"
data model. You will create JSPs that let you query and
update records and also view associated navigation functionality between the
pages.
Before starting this lesson, you should have completed the following:
1.
Install Oracle JDeveloper 10g.
2.
Install the sample schemas. This example
uses the HR schema included in the Oracle
database. The Sample Schemas installation guide is part of the Oracle
Database documentation set. You may also install the schema by following
the instructions found in the Installing
the Sample Schemas and Establishing a Database Connection
OBE lesson.
Creating a JSP Application with ADF Using a
Model 1 Architecture
When you work in JDeveloper, you organize your work in projects
within application workspaces. JDeveloper provides a number of predefined templates
which allow you to create a workspace and projects that are configured for developing
the types of application you are working on. The templates provide the basic
range of technologies that are needed, and you create your working environment
by selecting the one that fits your needs, then configuring it to add any additional
technologies you are going to use. The options that are available to you in
the New Gallery and for some context menu operations depend on your choice of
template for that workspace.
In this tutorial you are going to choose the basic workspace
and project creation with no predefined technology.
In the Applications Navigator, right-click
Applications and choose New from the
context menu.
2.
In the Create Workspace dialog, rename
the workspace Workspace1
to bc_jsp_1.
.(Notice that the directory name changes to match the new name.) Make
sure that the "Add a New Empty Project" checkbox is selected,
and click OK.
3.
In the Create Project dialog, rename the project name
Project1 to
Model1 and click OK.
Select the Model1 node in
the Navigator, and right-click to choose New to display
the New Gallery.
2.
In the New Gallery, open the Business Tier
node, select the Business Components category and double-click
the Business Components from Tables item.
3.
In the Business Components Project dialog, select the
connection that you created for the human resources (hr) schema, for example,
HRconnection, and click OK.
4.
The Create Business Components from Tables wizard appears.
Click Next on the Welcome page to begin.
5.
In the Entity Objects page, select the HR schema
from the dropdown menu of available database schema objects, and select
the Tables option as object types if it is not already
selected.
6.
Select the DEPARTMENTS
and EMPLOYEES tables in
the Available list and click the Move button to
move those selections to the Selected list. Click Next
to continue.
7.
In the View Objects page, move Departments
(HR.DEPARTMENTS) and Employees
(HR.EMPLOYEES) to the Selected
list. Click Next to continue.
8.
In the Application Module page, make no changes and click
Next.
9.
Click Finish to create the business components
in the Model1 project.
10.
Choose Run or Make to
compile, and save the project.
11.
Notice that JDeveloper displays the compilation information
at the bottom of the Messages window.
In these steps you will create a
JSP page to access the business components. The procedure shows how to create
a form that displays synchronized data between Departments and Employees views
using the Data Control Palette.
With the ModelClient1
project selected in the Applications Navigator, right-click and select
New to create a JSP.
2.
In the Categories tree, expand Web Tier and
select JavaServer Pages (JSP). In the Items list, double-click
JSP Page to open the Create JSP dialog.
3.
Leave the Directory Name field unchanged to save your
work in the directory where JDeveloper expects to find web application
files. In the File Name field, enter browse.jsp
as the name of the JSP file you want to generate and click OK.
4.
You now have a JavaServer Page that is opened in the Visual
Editor. A simple file named browse.jsp
is generated and appears in your active project.
5.
From the menu, choose View | DataControl
to display the Data Control palette.
6.
Select the DepartmentsView1
node in the Data Control Palette, and in the "Drag and Drop As"
list, select the "Read-only Form" option.
7.
Drag and Drop the DepartmentsView1
in the Design editor of the browse
JSP.
8.
Your JSP should look like this.
9.
In the"Drag and Drop As" list,
select the "Navigation Buttons" option.
10.
Drag and Drop the Navigation Buttons inside the form.
11.
The Navigation Buttons appear within the frame of the form.
12.
Expand the DepartmentsView1
node in the Data Control Palette, select the EmployeesView3
node and in the "Drag and Drop As" list, select the "Read-only
Table" option.
13.
Drag and Drop the
EmployeesView3 below the form.
14.
Your JSP should look like this:
15.
In the Applications Navigator, select the browse.jsp
node.
16.
Right-click and select the Run option
from the context menu.
17.
The JSP displays in the browser.
18.
Experiment with the navigation buttons.
19.
Close your browser.
Update the browse JSP to prepare
editing employee's details
Go back to the Design editor of the browse.jsp
page.
2.
Select the first cell of the new table, right-click and select
Table | Insert Column from the context menu.
3 .
In the Data Controlpalette, expand the
EmployeesView3
node, and open the Operations node.
4 .
Select the Operation setCurrentRowWithKey(value).
5 .
In the "Drag and Drop As" list, choose "Find
Row Link".
6 .
Drag and Drop the "setCurrentRowWithKey(value)"
operation in the lower row of the new column previously created.
7 .
Right-click on the Select
label and choose Edit Tag from the context menu.
8 .
In the Text field, enter Edit,
then click OK.
9 .
In the Data Control Palette, open the operations
node at the bottom of the palette.
10 .
Select the Commit operation and in the "Drag
and Drop As" list, choose the "Button with Form"
option.
11 .
Drag and drop the Commit operation in the
design editor at the bottom of the page.
12 .
Choose File | Save All to save all your
work thus far.
You now have a simple, working JSP page (named
browse.jsp) for browsing
the Departments and Employees view objects. At that point Employees are
synchronized with the Departments information being displayed. You have
also prepared the next step so that you can call an Edit page of the selected employee
and update the information. The browse page will allow you to commit
the changes that were done in the Edit page.
Step 3 - Create an updateable
JSP Based on the Employees View
The following steps show you how to create a detail JSP
page for Editing / Updating the Employees view object.
1.
Select the project Model1Client in the Applications
Navigator, where you will create another JSP, right-click and choose
New to open the New Gallery.
2.
In the Categories tree, expand Web Tier
(if necessary) and select JavaServer Pages (JSP).
3.
In the Items list, double-click JSP Page
to open the Create JSP dialog.
4.
Leave the Directory Name field unchanged to save your
work in the directory where JDeveloper expects to find web application
files. In the File Name field, enter editEmp.jsp
as the name of the JSP file you want to generate and click OK.
5 .
You now have another JSP page that is opened in the Design
editor. A simple file named editEmp.jsp
is generated and appears in your active project.
6.
In the Data Control Palette, select the EmployeesView3.
7.
In the "Drag and Drop As"list,
choose "Input Form".
8.
Drag and drop the
EmployeesView3 in the Design editor of the
editEmp JSP.
9.
The JSP should look like this:
10 .
Click the Source tab and locate the <body>
tag
11.
Below the <body>
tag add the following code to display error messages in the detail page:
Now you can run the browse jsp and select an employee
from the detail section, then edit the detail of the employee in a new page. The
editEmp page allows you to perform updates in the current employee's information
record.
1.
Select the
browse.jsp node in the Applications Navigator, right-click
and select the Run option from the context menu.
2.
Your browser should display the following master-detail
information.
3.
Experiment with the Navigation Buttons (Click Next
for example).
4.
Click on the Edit link for one of the
Employees.
5 .
The editEmp
is now displaying the Employee record.
6.
Make some change in the employee's record. (for instance,
update their salary) and click on the Submit button.
Note: If any of the input values has an error, then you should come back
to input page.
7.
In the case of no errors, the browse
page should display the new value for the employee.
8.
Click on the Commit button to validate
the change in the database.