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).
Online Store Application - Registering the Beans in the Application Configuration File (Page 7 of 11 )
You must register the MenuBean, SearchBean, BrowseBean, ProductBean, ProductDetailsBean, and OrderBean in the application configuration file, so that they can be instantiated properly. Listing 14-13 shows the managed-bean tags in the application configuration file.
Listing 14-13 Managed-Bean Registration in the Application Configuration File
The MenuBean has the application context because the instance is used by the whole application. The SearchBean, BrowseBean, ProductBean,and ProductDetailsBean have the request scope because they are specific to a particular user request. Notice that the ProductDetailsBean has its imageDir property set by using the managed-property tag. The ShoppingCartBean and OrderBean have the session scope because they must live throughout a user’s session.
Establishing Navigation Rules
You need navigation rules to manage the flow of your program. You use the JSP page names to define the navigation rules in the application file. Table 14-5 presents the JSP page name for each BuyDirect application page that needs navigation rules. (We will discuss these and the other JSP pages in the application in the “Creating the JSP Pages” section later in this chapter.)
Listing 14-14 shows the navigation-rule tags in the application configuration file.
Listing 14-14 Navigation Rules in the Application Configuration File
Table 14-5The JSP Filenames for BuyDirect Application Pages that Require Navigation Rules
Navigating to the Product Details Page
From the list of products in both the search page and browse page, users can click the Details hyperlink to view the details of a specific product. Therefore, you need the following two navigation rules:
After viewing the details of a product, users can decide to buy that product. Therefore, the details page must be able to navigate to the shopping cart page. This is made possible by the following navigation-rule tag: