Home arrow Java arrow Page 7 - Online Store Application
JAVA

Online Store Application


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

Author Info:
By: McGraw-Hill/Osborne
Rating: 5 stars5 stars5 stars5 stars5 stars / 54
March 16, 2005
TABLE OF CONTENTS:
  1. · Online Store Application
  2. · Understanding the Page Control Flow
  3. · Structuring the Database Tables
  4. · The DatabaseUtil Class
  5. · The MenuBean Class
  6. · The ShoppingItemBean Class
  7. · Registering the Beans in the Application Configuration File
  8. · Adding the ActionListener
  9. · Creating the JSP Pages
  10. · The search.jsp Page
  11. · The shoppingCart.jsp Page

print this article
SEARCH DEVARTICLES

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

<managed-bean>
  <managed-bean-name>MenuBean</managed-bean-name>
  <managed-bean-class>buydirect.MenuBean</managed-bean-class>
  <managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<managed-bean>
  <managed-bean-name>SearchBean</managed-bean-name> 
  <managed-bean-class>buydirect.SearchBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
  <managed-bean-name>BrowseBean</managed-bean-name> 
  <managed-bean-class>buydirect.BrowseBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
  <managed-bean-name>ProductBean</managed-bean-name>  
  <managed-bean-class>buydirect.ProductBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
  <managed-bean-name>ProductDetailsBean</managed-bean-name>
  <managed-bean-class>
   
buydirect.ProductDetailsBean
  </managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope> 
  <managed-property>
    
<property-name>imageDir</property-name>
    <value>images/</value>
  </managed-property>
</managed-bean>
<managed-bean>
 
<managed-bean-name>ShoppingCartBean</managed-bean-name> 
  <managed-bean-class>
    buydirect.ShoppingCartBean
  </managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
  <managed-bean-name>OrderBean</managed-bean-name> 
  <managed-bean-class>buydirect.OrderBean</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
</managed-bean>


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

<navigation-rule>
  <from-tree-id>*</from-tree-id>
  <navigation-case>
    <from-outcome>search</from-outcome>
    <to-tree-id>/search.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>
<navigation-rule>
  <from-tree-id>/search.jsp</from-tree-id>
  <navigation-case>
    <from-outcome>detail</from-outcome>
    <to-tree-id>/details.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>
<navigation-rule>
 
<from-tree-id>/browse.jsp</from-tree-id>
  <navigation-case>
    <from-outcome>detail</from-outcome>
    <to-tree-id>/details.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>
<navigation-rule>
  <from-tree-id>/details.jsp</from-tree-id>
 
<navigation-case>
    <from-outcome>buy</from-outcome>
    <to-tree-id>/shoppingCart.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>
<navigation-rule>
  <from-tree-id>/shoppingCart.jsp</from-tree-id>
  <navigation-case>
    <from-outcome>checkOut</from-outcome>
    <to-tree-id>/checkOut.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>
<navigation-rule>
 
<from-tree-id>/checkOut.jsp</from-tree-id>
 
<navigation-case>
    <from-outcome>order</from-outcome>
    <to-tree-id>/order.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>


The following sections discuss how these navigation rules work for each page.

Navigating to the Search Page

Every page allows users to search for a product. Therefore, any page can potentially navigate to the search.jsp page, and this is indicated by the following navigation-rule tag:

<navigation-rule>
  <from-tree-id>*</from-tree-id>
  <navigation-case>
   
<from-outcome>search</from-outcome>
    <to-tree-id>/search.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>

PageJSP Filename
Main pageindex.jsp
Search pagesearch.jsp
Browse pagebrowse.jsp
Product details pagedetails.jsp
Shopping cart pageshoppingCart.jsp
Check out pagecheckOut.jsp
Order pageorder.jsp

Table 14-5 The 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:

<navigation-rule>
  <from-tree-id>/search.jsp</from-tree-id>
  <navigation-case>
   
<from-outcome>detail</from-outcome>
    <to-tree-id>/details.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>
<navigation-rule>
  <from-tree-id>/browse.jsp</from-tree-id>
  <navigation-case>
    <from-outcome>detail</from-outcome>
    <to-tree-id>/details.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>

Navigating to the Shopping Cart Page

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:

<navigation-rule>
  <from-tree-id>/details.jsp</from-tree-id>
  <navigation-case>
   
<from-outcome>buy</from-outcome>
    <to-tree-id>/shoppingCart.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>

Navigating to the Check Out and Order Pages

From the shopping cart page, users can check out. The following navigation-rule tag defines the transition from the shopping cart page to the check out page.

<navigation-rule>
  <from-tree-id>/shoppingCart.jsp</from-tree-id>  
  <navigation-case>
    <from-outcome>checkOut</from-outcome>
    <to-tree-id>/checkOut.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>

Finally, after users enter their delivery and payment details, they can pay. This requires navigation from the check out page to the order page, enabled by the following navigation-rule tag:

<navigation-rule>
  <from-tree-id>/checkOut.jsp</from-tree-id>
  <navigation-case>
    <from-outcome>order</from-outcome>
    <to-tree-id>/order.jsp</to-tree-id>
  </navigation-case>
</navigation-rule>

-----------------------------------------------------------

This article is excerpted from JavaServer Faces Programming by Budi Kurniawan (McGraw-Hill, 2003; ISBN 0072229837). Check it out at your favorite bookstore today. Buy this book now.


blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials