Java
  Home arrow Java arrow Page 7 - Online Store Application
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Online Store Application
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 21
    2005-03-16

    Table of Contents:
  • Online Store Application
  • Understanding the Page Control Flow
  • Structuring the Database Tables
  • The DatabaseUtil Class
  • The MenuBean Class
  • The ShoppingItemBean Class
  • Registering the Beans in the Application Configuration File
  • Adding the ActionListener
  • Creating the JSP Pages
  • The search.jsp Page
  • The shoppingCart.jsp Page

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

    More Java Articles
    More By McGraw-Hill/Osborne


       · I go thru the online application, and I'm new to this topic, can anyone recreate...
     

    JAVA ARTICLES

    - 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 ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT