Download
FAQ History |
API
Search Feedback |
How the Pieces Fit Together
Previous sections of this chapter introduce you to the various parts of the application: the JSP pages, the backing beans, the listeners, the UI components, and so on. This section shows how these pieces fit together in a real application.
Chapters 17-21 of this tutorial use the Duke's Bookstore application (see The Example JavaServer Faces Application) to explain basic concepts of creating JavaServer Faces applications.
The example emulates a simple online shopping application. It provides a book catalog from which users can select books and add them to a shopping cart. Users can view and modify the shopping cart. When users are finished shopping, they can purchase the books in the cart.
Figure 17-3 shows how three components from two different pages of the Duke's Bookstore application are wired to back-end objects and how these objects are connected to each other on the server side. These pages and objects are shown in Table 17-3.
Figure 17-3 Duke's Bookstore Application Objects
The
bookstore6/web/bookcashier.jsp
page represents a form into which customers enter their personal information. The tag that represents thename
component on thebookcashier.jsp
page renders a text field. When a user enters a value in the field, aValueChangeEvent
is fired. Thebookstore6/src/listeners/NameChanged
value-change listener handles this event. The tag representing thename
component on the page binds the component's value to thename
property of thebookstore6/src/backing/CashierBean
using the value-binding expression"#{cashier.name}"
from itsvalue
attribute.The
bookcashier.jsp
page also includes aselectBooleanCheckbox
tag that renders thefanClub
component. This tag binds thefanClub
component instance to thespecialOffer
property ofCashierBean
using the value-binding expression"#{cashier.specialOffer}"
from itsbinding
attribute. When the customer clicks theSubmit
button on the page, thesubmit
method ofCashierBean
checks if the customer has ordered more than $100 (or 100 euros) worth of books. If he or she has, thefanClub
component and its label is rendered. This component allows the customer to choose to become a member in the Duke fan club as a reward for ordering more than $100 (or 100 euros) worth of books.The
fanClub
component's tag binds the component rather than its value to a backing bean property becauseCashierBean
must have access to therendered
property of thefanClub
component so that it can dynamically set the property totrue
. Because the component rather than the component value is bound to the backing bean property, the backing bean can manipulate the component properties more readily. Binding a Component Instance to a Bean Property provides more information on component binding.The
bookstore6/web/bookcatalog.jsp
page represents a form in which all the books in the database are displayed in a table. TheUIData
component generates this table, which contains a row for each book. See The UIData Component for information on how theUIData
component works. Each row also includes a button called Add to Cart, which the customer clicks to add the book to the cart. ThecommandButton
tag that renders each Add to Cart button references theadd
method ofCatalogBean
using the method-binding expression"#{catalog.add}"
from itsaction
attribute.When one of the Add to Cart buttons on the
bookcatalog.jsp
page is clicked, theadd
method ofCatalogBean
is invoked. This method updates the shopping cart.The
ShoppingCart
object is a model object, whose purpose is to handle application data, including retrieving data from the database.
Download
FAQ History |
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.