Step 10. Test the Application

In this step, we will complete the web project by importing some web components like DAO classes, JSPs and servlets. We will also create a server configuration, and deploy and run the Hibernate web application.

The tasks in this step are:

To Import and Edit Web Components (JSP and DAOs and so on.)

The following task adds the necessary packages, JSPs, and DAOs to complete your Hibernate web application for the purpose of this tutorial.

  1. Create the following java packages:
  2. Copy all the classes from the workshop-hibernate-tutorial/web/Resources/dao-classes folder to the com.bea.dao package. The classes under this package manage object persistence using Hibernate.
  3. Similarly, copy the MessageFactory class from the workshop-hibernate-tutorial/web/Resources/util folder to the com.bea.util package.
  4. Copy all the JSPs from the workshop-hibernate-tutorial/web/Resources/JSPs folder to workshop-hibernate-tutorial/web/pages folder.
  5. Switch to the Project Explorer view for this step. Copy the workshop-hibernate-tutorial/web/Resources/stylesheet.css file to the web folder.
  6. Switch to the AppXplorer view copy the workshop-hibernate-tutorial/web/Resources/application.properties file and overwrite to application.properties file under the workshop-hibernate-tutorial > web/WEB-INF/src/java > resources folder.
  7. Create a new class CustomerManagedBean under the com.bea.beans package.
  8. Add the following code to the CustomerManagedBean class:
    private com.bea.beans.Customer customer;
    
    public com.bea.beans.Customer getCustomer() {
        return customer;
    }
    
    public void setCustomer(com.bea.beans.Customer customer) {
        this.customer = customer;
    }
  9. Add the following import statements to the CustomerManagedBean class:
    import javax.faces.application.FacesMessage;
    import javax.faces.context.ExternalContext;
    import javax.faces.context.FacesContext;
    import com.bea.dao.CustomerDAO;
    import com.bea.dao.DAOException;
    import com.bea.dao.DAOFactory;
    import com.bea.dao.OrderDAO;
    import com.bea.util.MessageFactory;
  10. Copy the methods from workshop-hibernate-tutorial/web/Resources/BackingBean_Customer_Methods.txt file into the CustomerManagedBean class.
  11. Save CustomerManagedBean.java file.

Edit the Faces Deployment Descriptor

  1. You need to define Managed Beans and Navigation Rules in faces-config.xml file.
  2. The web/Resources folder contains the faces-config.xml file with Managed Bean configurations and Navigation Rules for the web application. Copy (and overwrite) web/Resources/faces-config.xml to web/WEB-INF/config folder.

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.


Deploy the Hibernate Web Application

  1. To run the application, right-click workshop-hibernate-tutorial in the Project Explorer view and choose Run As > Run on Server.
  2. In the Run On Server, click Finish.
  3. Once the server starts successfully, the test browser pane opens. Enter the address http://localhost:7001/pages/addCustomer.jsf in the address line of the test browser pane (http://localhost:8080/pages/addCustomer.jsf if you are running on Tomcat 5.5).
  4. It may be necessary to update the hsqlDB folder for a successful deployment. To update the hsqlDB folder: switch to the AppXplorer view, right-click workshop-hibernate-tutorial/web/hsqlDB and select Refresh.

To Run the Application

  1. Once the addCustomer JSF page loads, you will see the screen below.

  2. To add a new customer, enter the name Bob and click Submit.

    The application calls the addCustomer( ) action method of the Customer managed bean and forwards the request to viewAllCustomers.jsp. The viewAllCustomers.jsp gets the customers list using the <h:dataTable> component and displays it as shown below

  3. You can also observe the debugging messages at the Console view in Workshop. Note: we have enabled the hibernate.show_sql property to display SQL statements.

  4. Click the View Orders button for the customer name JOHN to get the list of order(s) placed by JOHN.
  5. Click Back to return to the previous page and a get list of orders placed by other customers.
  6. Once you are done, stop the server.

Click one of the following arrows to navigate through the tutorial:


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