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 steps you through the development of a Human
Resources application using Toplink, Struts, and JSPs.
You have been given the task of creating a Human Resources
application that can be deployed to multiple platforms, and can use any type
of client. To accomplish this task you'll create an application using the Model-View-Controller
(MVC) architecture. You will create the model using Toplink to generate classes
from database tables. You'll use the struts controller and will implement the
view using JSP pages.
In this step you'll create a new application workspace to
organize your application. You'll also create a new EJB
diagram for your business tier objects. A diagram gives you a visual representation
of your business objects, helping you to conceptualize the application. Once
the EJB Diagram is created, you'll start building persistent business objects
as entity beans.
In the Application Navigator, right-click the Applications node and choose
New Application Workspace. The Create Application Workspace dialog
opens.
Change the Application Name to TopLinkHRApplication
In the Application Package Prefix field, type hr.
In the Application Templates field, choose No Template[All Technologies]
from the dropdown list.
Click OK.
A new project called Project1 is created.
2.
From the File menu, select Rename and name this project TopLinkModel.
Click Save.
3.
The next step is to notify the IDE that TopLink is one of the technologies
used by this project. This enables the IDE to provide smart choices as
you develop your application.
Double-click on TopLinkModel in the navigator to access the Project
Properties dialog.
Select the Technology Scope node in the Project Properties dialog.
Select TopLink in Available Technologies and move it to Selected
Technologies.
Select Java in Available Technologies and move it to Selected Technologies.
4.
Modify the Default Package (under Common -> Input paths) to
hr.model
In the Application Navigator, right-click TopLinkModel (under
the TopLinkHRApplication node) and select New...
The New Gallery opens.
In the New Gallery, under the Categories list, expand General, and select
Diagrams. In the Items list, select Java Class Diagram.
Click OK. The Create Java Class Diagram dialog opens.
2.
Accept the default package name, but change the name of the diagram to
TopLink HR Diagram.
Click OK.
3.
From the File menu, choose Save All.
4.
Note: If you have not established a connection to the HR schema, please
see the prerequisites section.
In the Navigator, click the Connections tab. This will bring the
Connection Navigator to the front.
In the Connection Navigator, expand the nodes for Database, tutorial_jdbc_connection,
hr, and Tables. Click on DEPARTMENTS and then Ctrl-click
EMPLOYEES. Drag and drop both onto the blank Java Class diagram.
The Create from Tables dialog opens.
5.
In the Create from Tables dialog, select Java Classes and
click OK.
The new Java class beans appear on the diagram.
Optionally, arrange the objects in the diagram by clicking and dragging
the diagram elements so that they are easier to see. You can straighten
the relationship lines by right-clicking a line and choosing Straighten
Lines.
6.
In the Navigator, click on the Applications tab and you'll notice
that two new nodes, Departments.java,
and Employees.java, appear
in the Application Navigator underneath the hr.model
package.
A new package HR is created which contains offline database tables.
7.
From the File menu, choose Save All.
Generate TopLink Deployment
and Session Descriptors
The data control layer exposes the business services
to clients. The data control is technology specific, so there are different
data controls for TopLink, EJBs, JavaBeans, ADF business components, etc. Additionally,
the data bindings are client agnostic. This means that no matter what kind of
technology the business services were developed with, a client can interact
with any of them seamlessly.
The ADF framework creates the data bindings for you, so the
only thing you need to do is create the data control.
1.
Open the Data Control Palette by selecting View ->
Data Control Palette.
2.
Drag Departments.java from the Application Navigator and drop
it onto the Data Control Palette.
Select Sessions Configuration and specify Location as sessions.xml
and Sessions as HRSession.
Click OK.
3.
From the File menu, choose Save All.
4.
Take a look at the Application Navigator and you'll notice a few new
files, Departments.xml
and Employees.xml (under
the hr.model package), which contain the metadata for the methods
and accessors.
In this step you'll create the view and controller part of
this HR application. The controller separates the visual representation of web
pages from their flow and actions. From the home page of this application, the
user will be able to navigate to a JSP page which will show a list of all Departments.
Selecting one of the departments will forward the user to a JSP containing a
form for editing Department data. Finally, you'll create a JSP which displays
a list of employees by department. This demonstrates master-detail navigation
in a data-bound Struts JSP application.
Select the TopLinkHRApplication node, right-click and choose New
Project.
In the New Gallery, under the Categories list, expand General, and select
Projects. In the Items list, select Empty Project.
Click OK.
2.
Name this project ViewController and click OK to create
the project.
3.
Now notify the IDE that Struts and JSP are the technologies used by this
project.
Double-click on ViewController in the navigator to access the
Project Properties dialog.
Select the Technology Scope node.
Select Struts in Available Technologies and move it to Selected
Technologies.
Select JavaServer Pages (JSP) and Servlets in Available Technologies
and move it to Selected Technologies.
Select Hyper Text Markup Language (HTML) in Available Technologies
and move it to Selected Technologies.
4.
Modify the Default Package (under Common -> Input paths) to view
Click OK. This will setup your project for Struts development.
5.
In the Application Navigator, right click the ViewController project
and select Open Struts Page Flow Diagram... A blank Page Flow Diagram
opens.
In the Component Palette select the Page component and add it
to the Page Flow Diagram by clicking in the diagram. This creates a JSP
page called /untitled1. Click within the name to change it to /home.jsp
6.
In the Component Palette select the Data Page component and click
on the diagram. Name this new Page /browseDept.
7.
Double-click /home.jsp to create the JSP page and open it in the
visual JSP editor.
Optionally, add the text Home Page of My HR Application to the
JSP. Add a style sheet and modify the JSP page as needed.
8.
Open the Page Flow Diagram to draw the page flow between the shapes.
Choose the Page Link component on the Component Palette, and click
on the /home.jsp action. Drag the link to the /browseDept
Data Page and click again. (This will create a link in the home page which
will invoke the /browseDept Data Page)
9.
Double-click /browseDept to create the JSP page. Accept the default
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.
10.
In the Data Control Palette, select return from the readAllDepartments()
node.
In the Drag and Drop As dropdown list, select Read-Only Table.
11.
Drag and drop the return node from the Data Control Palette onto
the browseDept page.
12.
The ApplicationResources.properties file contains messages that we will
be using in the application. Change the properties file to have a user
friendly link in the home.jsp JSP page.
Double-click ApplicationResources.properties under the view
package in the Application Navigator.
13.
Change the value of link.browseDept to Click here to browse
Departments.
14.
In the Page Flow Diagram, select the /home.jsp icon. Right-click
and select Run.
Next create a JSP to display an input form to edit the department information.
Select the DataPage component from the component palette and add
it to the Page Flow Diagram. Change the name to /editDept.
2.
Choose the Forward component in the Component Palette, click on
/browseDept, drag the forward component to the /editDept Data
Page, and click again.
3.
Rename the forward setCurrentRowWithKey.
4.
Choose the Forward component in the Component Palette, click on
/editDept, drag the forward component to the browseDept Data
Page, and click again. Rename the forward Submit.
5.
Double-click /browseDept to open it in the editor.
In the Data Control Palette, select setCurrentRowWithKey(String)
from the Operations node of return.
In the Drag and Drop As dropdown list, select Find Row Link.
6.
Drag the Find Row Link from the Data Control Palette onto the
browseDept.jsp page, just in front of the Row.DepartmentId field and change
the text of the link to Edit.
7.
In the Page Flow Diagram, double click /editDept and click OK
to to create the corresponding JSP page and open it in the visual editor.
Optionally, add Edit Department Information to the JSP. Add a style
sheet and modify the JSP page as needed.
8.
In the Data Control Palette, select the return node from readAllDepartments().
In the Drag and Drop As dropdown list, select Input Form.
9.
Drag return from the Data Control Palette onto the editDept.jsp
page.
10.
In the Application Navigator, double-click browseDept to open
it in the visual editor.
In the Data Control Palette, expand the Operations node and click Commit.
11.
Drag the Commit button onto browseDept.jsp. Click Yes to
create the button inside a form.
12.
In the Data Control Palette, select the Rollback button and drag
it onto browseDept.jsp, within the same form as the commit button.
13.
Select the form and in the property inspector, select browseDept.do
in the action dropdown.
14.
In the Page Flow Diagram, right-click /home.jsp and select Run.
Click on the link Click Here to Browse Departments in the home
page.
You will see the list of departments. Notice the * next to the department
number. This identifies the current row.
15.
Click on the Edit for a department number.
You will see the edit page which has the information related to department
number you have selected.
16.
Update department information and click Submit.
This enables the Commit and Rollback buttons. Click Commit.
Open the Page Flow Diagram.
In the Component Palette, select the Data Page component and click
on the diagram. Name this new Data Page /browseEmp.
2.
Choose the Page Link component in the Component Palette, click
on the /home.jsp action, drag the link to /browseEmp and
click again. (This will create a link in the home page which will invoke
the /browseEmp Data Page).
3.
Double-click on /browseEmp to create the
JSP page.
Optionally, add the text List of Employees by Department to the JSP.
Add a style sheet and modify the JSP page as needed.
4.
In the Data Control Palette, select return from the readAllDepartments()
node
In the Drag and Drop As dropdown list, select Read-Only Form.
5.
Drag and drop the return node from the
Data Control Palette onto the browseEmp JSP page.
6.
In the Data Control Palette, select return from the readAllDepartments()
node.
In the Drag and Drop As dropdown list, select Navigation Buttons.
7.
Drag return to the browseEmp JSP page.
(Make sure that the buttons are dropped within the boundaries of the Form).
8.
In the Data Control Palette, select the employeesCollection node.
In the Drag and Drop As dropdown list, select Read-Only Table.
9.
Drag employeesCollection onto the browseEmp JSP page, beneath
the Departments form.
10.
Change the ApplicationResources.properties
file to have a user-friendly link in the home.jsp page.
Select ApplicationResources.properties under the view
package in the Application Navigator.
Change the value of link.browseEmp to Click here to see the list of Employees by Department.
11.
From the File menu, choose Save All.
12.
In the Page Flow Diagram, right-click /home.jsp and select Run.
Click on the link you just created.
In the employees list page, click on the navigation buttons to see the
employees in different departments.
In this lesson, you learned how to generate Java classes
from database tables using Toplink, create a Page Flow using the Struts Controller,
and how to create JSP pages which are bound to data using ADF databinding.