Step 6. Connecting Entities to a User Interface

Time to complete this step: 30 minutes

In this step, we will import a web application that incorporates the database connection, entities and Java classes we've created in this tutorial. This application includes DAO classes, JSPs and servlets. After importing the application, we will create a new server and run the application.

The tasks you will complete in this step are:

To Import the Web Application

  1. Import web.zip into the web application workshop-jpa-tutorial from the Resources folder under path workshop-jpa-tutorial/web.
  2. Right click on the project workshop-jpa-tutorial. Select Import > General > Archive File and click Next. Browse to <your workspace location>/workshop-jpa-tutorial/web/Resources/web.zip and click Finish. Overwrite the faces-config.xml and the application.properties as you import.

To Review the Application Components

The imported application includes data access objects and a managed bean. The project is also completed by the importing of a faces-config.xml file which manages the navigation of the application and the JSPs that comprise the user interface.

Review the DAO Layer

For the web application project workshop-jpa-tutorial the Data Access Layer objects are in the package com.bea.dao. Review the objects in this package.

The DAO layer is responsible for providing access to the backend database using Kodo JPA which is an Oracle implementation of Sun's Java Persistence API (JPA) specification for the transparent persistence of Java objects.

Review the MVC connection strategy: Using DAO through a JSF Managed Bean

The web/WEB-INF/config folder contains the faces-config.xml file that configures the Managed Bean configurations and Navigation Rules for the web application.

  1. Right-click the faces-config.xml file and select Open With > Workshop XML editor to review the Faces configurations. Note that Customer and CustomerManagedBean are defined as managed beans in the request scope. Also, DAOFactory is defined as a managed bean in the application scope.
  2. Navigation Rules are defined for addCustomer.jsp and viewAllCustomers.jsp. The navigation case for addCustomer.jsp specifies /pages/viewAllCustomers.jsp as the destination page while the outcome is success.

  3. Similarly, the navigation case for viewAllCustomers.jsp describes /pages/viewOrders.jsp as the destination page while the outcome is orderList.

 

Configure WebLogic Server

In this step you will add a WebLogic Server domain for use with Workshop. This server domain contains runtime libraries required by the application and the application will be deployed to this server.


To Run the JPA Web Application

  1. To run your application, right-click the workshop-jpa-tutorial in the AppXplorer and choose Run As > Run on Server.
  2. In the Define Server dialog, use the default Choose an existing server setting for localhost > WebLogic Server v10.3 @ localhost and click Finish.
  3. After the server starts successfully, the test browser pane opens. Enter the address http://localhost:7001/workshop-jpa-tutorial/pages/addCustomer.jsf in the address line of the test browser pane to view the addCustomer.jsf page in the browser.

  4. Enter the name Bob and clicking Submit to add a new customer named Bob.
  5. The application calls addCustomer( ) action method of the CustomerManagedBean and forwards the request to viewAllCustomers.jsp, if the customer is added successfully. The viewAllCustomers.jsp gets the customers list using the <h:dataTable> component and displays it as shown below.

  6. Click View Orders for the customer name JOHN to get the list of order(s) placed by JOHN.

  7. Click Back to browse to the previous page and view orders placed by other customers.
  8. Once you are done, stop the server.

Click the arrow to navigate to the previous step in the tutorial:

 


Still need help? Post a question on the Workshop newsgroup.