Legal | Privacy
Creating a JSP Application with ADF Using a Model 1 Architecture

Creating a JSP Application with ADF Using a Model 1 Architecture

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 an easy way of establishing the business services for this example.

Approximately 1 hour

Topics

The tutorial will discuss the following:

Overview
Prerequisites
Create a Business Components Project

Create a Master Detail JSP in a new Project

Create an updateable JSP based on the Employees View
Run your JSP Pages
Summary

Overview

The goal of this tutorial is to teach you how to build a JSP application with JDeveloper using a Model 1 environment.

Back to Topic List

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.

Prerequisites

Back to Topic List

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.

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.

Note: If you open all the screenshots, response time may be slow depending on your Internet connection.

 

Create a Business Components Project

Back to Topic List

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.

Create a new Workspace with an empty project for the model
Create the business components

Create a new Workspace with an empty project for the model

Back to List

1.

In the Applications Navigator, right-click Applications and choose New from the context menu.

Move your mouse over this icon to see the image


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.

Move your mouse over this icon to see the image

 

3.

In the Create Project dialog, rename the project name Project1 to Model1 and click OK.

Move your mouse over this icon to see the image

Save your work.

 

Create the business components

Back to List

1.

Select the Model1 node in the Navigator, and right-click to choose New to display the New Gallery.

Move your mouse over this icon to see the image


2.

In the New Gallery, open the Business Tier node, select the Business Components category and double-click the Business Components from Tables item.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

4.

The Create Business Components from Tables wizard appears. Click Next on the Welcome page to begin.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

7.

In the Updateable View Objects page, move Departments (HR.DEPARTMENTS) and Employees (HR.EMPLOYEES) to the Selected list. Click Next to continue.

Move your mouse over this icon to see the image

 

8.

Click Next on the Read Only View Objects From Tables page, and in the Application Module page, make no changes and click Next.

Move your mouse over this icon to see the image

 

9.

Click Finish to create the business components in the Model1 project.

Move your mouse over this icon to see the image

 

10.

Choose Run or Make to compile, and save the project.

Move your mouse over this icon to see the image

 

11.

Notice that JDeveloper displays the compilation information at the bottom of the Messages window.

Move your mouse over this icon to see the image

 

 

 

Create a JSP in a new Project

Back to Topic List

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.

Create a new Project for the JSPs
Create a Master-Detail JSP based on Departments and Employees views
Update the browse JSP to edit employee's details

 

Create a New Project for the JSPs

Back to List

1.

Select the bc_jsp_1 Application node in the Applications Navigator, right-click the folder and choose New Project.

Move your mouse over this icon to see the image


2.

In the New Gallery, in the Categories expand the General node, select Projects and choose Empty Project as the item.

Move your mouse over this icon to see the image

 

3.

In the Create Project dialog, rename the project name Project1 to Model1Client and click OK.

Move your mouse over this icon to see the image

Save your work.

 

 

Create a Master-Detail JSP based on Departments and Employees Views

Back to List

1.

With the ModelClient1 project selected in the Applications Navigator, right-click and select New to create a JSP.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

5.

From the menu, choose View | Data Control to display the Data Control palette.

Move your mouse over this icon to see the image

 

6.

Select the DepartmentsView1 node in the Data Control Palette, and in the "Drag and Drop As" list, select the "Read-only Form" option.

Move your mouse over this icon to see the image

 

7.

Drag and Drop the DepartmentsView1 in the Design editor of the browse JSP.

Move your mouse over this icon to see the image

 

8.

Your JSP should look like this.

Move your mouse over this icon to see the image

 

9.

In the "Drag and Drop As" list, select the "Navigation Buttons" option.

Move your mouse over this icon to see the image

 

10.

Drag and Drop the Navigation Buttons inside the form.

Move your mouse over this icon to see the image

 

11.

The Navigation Buttons appear within the frame of the form.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

13.

Drag and Drop the EmployeesView3 below the form.

Move your mouse over this icon to see the image

 

14.

Your JSP should look like this:

Move your mouse over this icon to see the image

 

15.

In the Applications Navigator, select the browse.jsp node.

Move your mouse over this icon to see the image

 

16.

Right-click and select the Run option from the context menu.

Move your mouse over this icon to see the image

 

17.

The JSP displays in the browser.

Move your mouse over this icon to see the image

 

18.

Experiment with the navigation buttons.

Move your mouse over this icon to see the image

 

19.

Close your browser.

 

 

 

Update the browse JSP to prepare editing employee's details

Back to List

1.

Go back to the Design editor of the browse.jsp page.

Move your mouse over this icon to see the image

 

2.

Select the first cell of the new table, right-click and select Table | Insert Column from the context menu.

Move your mouse over this icon to see the image

 

3 .

In the Data Control palette, expand the EmployeesView3 node, and open the Operations node.

Move your mouse over this icon to see the image

 

4 .

Select the Operation setCurrentRowWithKey(value).

Move your mouse over this icon to see the image

 

5 .

In the "Drag and Drop As" list, choose "Find Row Link".

Move your mouse over this icon to see the image

 

6 .

Drag and Drop the "setCurrentRowWithKey(value)" operation in the lower row of the new column previously created.

Move your mouse over this icon to see the image

 

7 .

Right-click on the Select label and choose Edit Tag from the context menu.

Move your mouse over this icon to see the image

 

8 .

In the Text field, enter Edit, then click OK.

Move your mouse over this icon to see the image

 

9 .

In the Data Control Palette, open the operations node at the bottom of the palette.

Move your mouse over this icon to see the image

 

10 .

Select the Commit operation and in the "Drag and Drop As" list, choose the "Button with Form" option.

Move your mouse over this icon to see the image

 

11 .

Drag and drop the Commit operation in the design editor at the bottom of the page.

Move your mouse over this icon to see the image

 

12 .

Choose File | Save All to save all your work thus far.

Move your mouse over this icon to see the image

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.

 

 

Create an updateable JSP Based on the Employees View

Back to Topic List

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.

Move your mouse over this icon to see the image

 

2.

In the Categories tree, expand Web Tier (if necessary) and select JavaServer Pages (JSP).

Move your mouse over this icon to see the image

 

3.

In the Items list, double-click JSP Page to open the Create JSP dialog.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

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.

Move your mouse over this icon to see the image

 

6.

In the Data Control Palette, select the EmployeesView3.

Move your mouse over this icon to see the image

 

7.

In the "Drag and Drop As" list, choose "Input Form".

Move your mouse over this icon to see the image

 

8.

Drag and drop the EmployeesView3 in the Design editor of the editEmp JSP.

Move your mouse over this icon to see the image

 

9.

The JSP should look like this:

Move your mouse over this icon to see the image

 

10 .

Click the Source tab and locate the <body> tag

Move your mouse over this icon to see the image

 

11.

Below the <body> tag add the following code to display error messages in the detail page:

<P>
  <c:forEach var="exception" items="${bindings.exceptionsList}">
   <c:out value="${exception.message}"/>
    <p>
     <c:forEach var="e1" items="${exception.details}">
      <c:out value="${e1.message}"/>
       <p>
        <c:forEach var="e2" items="${e1.details}">
         <c:out value="${e2.message}"/>
        </c:forEach>
       </p>
     </c:forEach>
    </p>
  </c:forEach>
</P>

Move your mouse over this icon to see the image

 

12.

Click on the Design tab to view the JSP.

Move your mouse over this icon to see the image

 

13.

Select the project Model1Client in the Applications Navigator, where you will create a Java Class, right-click and choose New to open the New Gallery.

Move your mouse over this icon to see the image

 

14.

In the New Gallery, expand the General node, select the Simple Files category and double click the Java Class Item.

Move your mouse over this icon to see the image

 

15.

In the Create Java Class dialog, enter MyLifeCycle in the Name field.

Move your mouse over this icon to see the image

 

16.

In the Extends field, click the Browse button to open the Class Browser.

Move your mouse over this icon to see the image

 

17.

Scroll down to the oracle node, and open successively the adf | controller | lifecycle nodes and select the PageLifeCycle Class, then click OK.

Move your mouse over this icon to see the image

 

18.

Click OK again to validate the creation of the Java Class.

Move your mouse over this icon to see the image

 

19.

Select the Source tab of the class MyLifeCycle.

Move your mouse over this icon to see the image

 

20.

Cut and paste the following import statements:

import oracle.adf.controller.lifecycle.LifecycleContext;

Cut and paste the following java code statements above the last } character:

public void onSetCurrentRowWithKey(LifecycleContext ctx)
   {
     super.invokeActionBinding(ctx, "setCurrentRowWithKey");
     ctx.setForwardPath("editEmp.jsp");
     ctx.setRedirect(true);
   }

   public void onSubmit(LifecycleContext ctx)
   {
     if (!this.hasErrors(ctx))
       {
         ctx.setForwardPath("browse.jsp");
         ctx.setRedirect(true);
       }
   }

Move your mouse over this icon to see the image

 

21.

In the Applications Navigator, select the browse.jsp node.

Move your mouse over this icon to see the image

 

22.

In the Structure pane, select the adf:uimodelreference node.

Move your mouse over this icon to see the image

 

23.

From the Menu, select View | Property Inspector to open the Property Inspector.

Move your mouse over this icon to see the image

 

24.

In the Property Inspector, select the lifecycle property.

Move your mouse over this icon to see the image

 

25.

In the lifecycle dialog, click the Browse button.

Move your mouse over this icon to see the image

 

26.

In the Class Browser, open the node mypackage2 and select the class MyLifeCycle , then OK.

Move your mouse over this icon to see the image

 

27.

The new property should appear in the Property Inspector.

Move your mouse over this icon to see the image

 

28.

In the Applications Navigator, select the editEmp.jsp node.

Move your mouse over this icon to see the image

 

29.

In the Structure pane, select the adf:uimodelreference node.

Move your mouse over this icon to see the image

 

30 .

In the Property Inspector, select the lifecycle property.

Move your mouse over this icon to see the image

 

31 .

In the lifecycle dialog, click the Browse button.

Move your mouse over this icon to see the image

 

32 .

In the Class Browser, open the node mypackage2 and select the class MyLifeCycle , then OK.

Move your mouse over this icon to see the image

 

33 .

The new property should appear in the Property Inspector.

Move your mouse over this icon to see the image

 

34 .

Save your work.

Move your mouse over this icon to see the image

 

 

Run your JSP pages

Back to Topic List

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.

Move your mouse over this icon to see the image

 

2.

Your browser should display the following master-detail information.

Move your mouse over this icon to see the image

 

3.

Experiment with the Navigation Buttons (Click Next for example).

Move your mouse over this icon to see the image

 

4.

Click on the Edit link for one of the Employees.

Move your mouse over this icon to see the image

 

5 .

The editEmp is now displaying the Employee record.

Move your mouse over this icon to see the image

 

6.

Make some change in the employee's record. (for instance, update their salary) and click on the Submit button.

 

Move your mouse over this icon to see the image

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.

Move your mouse over this icon to see the image

 

8.

Click on the Commit button to validate the change in the database.

Move your mouse over this icon to see the image

 

 

 

Back to Topic List

In this lesson, you've learned how to:

Create a Master-Detail relationship in a new Project
Create an updateable JSP that uses the Model 1 architecture
Run the JSP pages

 

 

Move your mouse over this icon to hide all screenshots