If you want to build an online store application using Java, look no further. This article begins with an overview of the application, and then discusses the applicatin development process. It is taken from chapter 14 of JavaServer Faces Programming by Budi Kurniawan (McGraw-Hill, 2003; ISBN 0072229837).
In the previous chapters, you have learned the basics of JSF and how to build each component of a JSF application. To illustrate the use of JSF in the real world, this chapter presents an online store application named BuyDirect, an Internet store that sells electronic goods.
This chapter begins with an overview of the application, and then discusses the application development process. We will cover page design, database design and access, model objects, the application configuration file entries for bean registration and navigation rules, the deployment descriptor, and the JSP pages.
Introducing the BuyDirect Application
The BuyDirect application allows users to do the following:
Search for certain products based on product names or descriptions.
Browse the list of products by category.
View a productís details.
Add a product to the shopping cart.
View the shopping cart.
Check out and place an order.
The main objective of this application is to show how to use JSF in a real-world application. Admittedly, the application is not a complete solution yet. For example, you cannot edit the shopping cart, and it lacks an administration section for changing the product information and handling the orders. However, it provides basic functionality, and finalizing it should not be difficult.
The BuyDirect application has ten JSP pages, one ActionListener (AppActionListener), one context listener (AppContextListener), and eight JavaBeans. In addition, there are also the deployment descriptor and the JSF application configuration file, as well as a number of image files in the images directory. Figure 14-1 shows the directory structure of this application.
Designing the Application Pages
For consistency, each page in the BuyDirect application uses the same design. There is a header at the top of the page and a menu on the left side. The page template is shown in Figure 14-2.
Here are the HTML tags that make up the page:
<html> <head> <title><!-- The title --></title> </head> <body> <table> <tr> <td colspan="2"> <!-- The header --> </td> </tr> <tr> <td valign="top"> <!-- The menu --> </td> <td valign="top"> <!-- Content --> </td> </tr> <tr> <td colspan="2"> <!-- The footer --> </td> </tr> </table> </body> </html>
Each page in the application links to a Cascading Style Sheet (CSS) file called Styles.css, residing in the application directory. Using a style sheet provides a more flexible way of formatting than embedding formatting directly on the page. The Styles.css file is shown in Listing 14-1.