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.
- Create the following java packages:
- 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.
- Similarly, copy the MessageFactory class from the workshop-hibernate-tutorial/web/Resources/util folder
to the com.bea.util package.
- Copy all the JSPs from the workshop-hibernate-tutorial/web/Resources/JSPs folder to workshop-hibernate-tutorial/web/pages folder.
- Switch to the Project Explorer view for this step. Copy the workshop-hibernate-tutorial/web/Resources/stylesheet.css file
to the web
folder.
- 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.
- Create a new class CustomerManagedBean under the com.bea.beans package.
- 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;
}
- 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;
- Copy the methods from workshop-hibernate-tutorial/web/Resources/BackingBean_Customer_Methods.txt file
into the CustomerManagedBean class.
- Save CustomerManagedBean.java file.
Edit the Faces Deployment Descriptor
- You need to define Managed Beans and Navigation Rules in faces-config.xml file.
- 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
- To run the application, right-click workshop-hibernate-tutorial in
the Project
Explorer view and choose Run As > Run on Server.
- In the Run On Server, click Finish.
- 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).
- 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
- Once the addCustomer JSF page loads, you will see the screen below.

- 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

- 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.

- Click the View Orders button for the customer name JOHN
to get the list of order(s) placed by JOHN.
- Click Back to return to the previous page and a get list
of orders placed by other customers.
- 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.