background image

The CoffeeBreakBean JavaBeans Component

<< The RetailPriceList JavaBeans Component | The managed-bean element >>
<< The RetailPriceList JavaBeans Component | The managed-bean element >>

The CoffeeBreakBean JavaBeans Component

CoffeeBreakBean.CB_RESOURCE_BUNDLE_NAME,
"EMailError");
context.addMessage(toValidate.getClientId(context),
new FacesMessage(message));
}
}
The CoffeeBreakBean JavaBeans Component
CoffeeBreakBean
acts as the backing bean to the JSP pages. See
"Backing Beans" on page 309
for more information on backing beans. CoffeeBreakBean creates the ShoppingCart object,
which defines the model data for the components on the orderForm page that hold the data
about each coffee. CoffeeBreakBean also loads the RetailPriceList object. In addition, it
provides the methods that are invoked when the buttons on the orderForm and checkoutAck
are clicked. For example, the checkout method is invoked when the Checkout button is clicked
because the tag corresponding to the Checkout button refers to the checkout method by means
of its action attribute:
<h:commandButton id=
"checkoutLink" value="#{CBMessages.Checkout}"
action=
"#{CoffeeBreakBean.checkout}" />
The checkout method returns a String, which the JavaServer Faces page navigation system
matches against a set of navigation rules to determine what page to access next. The navigation
rules are defined in a separate XML file, described in
"Resource Configuration" on page 1050
.
The RetailPriceListServlet Servlet
RetailPriceListServlet
responds to requests to reload the price list via the URL
/loadPriceList
. It simply creates a new RetailPriceList and a new ShoppingCart.
Because this servlet would be used by administrators of the Coffee Break server, it is a protected
web resource. To load the price list, a user must authenticate (using basic authentication), and
the authenticated user must be in the admin role.
Resource Configuration
A JavaServer Faces application usually includes an XML file that configures resources for the
application. These resources include JavaBeans components, navigation rules, and others.
Two of the resources configured for the JavaServer Faces version of the Coffee Break server are
the CheckoutForm bean and navigation rules for the orderForm page:
<managed-bean>
<managed-bean-name>checkoutFormBean</managed-bean-name>
<managed-bean-class>
Coffee Break Server
The Java EE 5 Tutorial · September 2007
1050