10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Coffee Break Server<br />

1042<br />

}<br />

}<br />

CoffeeBreakBean.CB_RESOURCE_BUNDLE_NAME, "EMailError");<br />

context.addMessage(toValidate.getClientId(context),<br />

new FacesMessage(message));<br />

<strong>The</strong> CoffeeBreakBean <strong>Java</strong>Beans Component<br />

CoffeeBreakBean acts as the backing bean to the JSP pages. See “Backing Beans” on page 307<br />

for more information on backing beans. CoffeeBreakBean creates the ShoppingCart object,<br />

which defines the model data for the components on the orderForm page that hold the data<br />

about each coffee. CoffeeBreakBean also loads the RetailPriceList object. In addition, it<br />

provides the methods that are invoked when the buttons on the orderForm and checkoutAck<br />

are clicked. For example, the checkout method is invoked when the Checkout button is clicked<br />

because the tag corresponding to the Checkout button refers to the checkout method by means<br />

of its action attribute:<br />

<br />

<strong>The</strong> checkout method returns a String, which the <strong>Java</strong>Server Faces page navigation system<br />

matches against a set of navigation rules to determine what page to access next. <strong>The</strong> navigation<br />

rules are defined in a separate XML file, described in “Resource Configuration” on page 1042.<br />

<strong>The</strong> RetailPriceListServlet Servlet<br />

RetailPriceListServlet responds to requests to reload the price list via the URL<br />

/loadPriceList. It simply creates a new RetailPriceList and a new ShoppingCart.<br />

Because this servlet would be used by administrators of the Coffee Break server, it is a protected<br />

web resource. To load the price list, a user must authenticate (using basic authentication), and<br />

the authenticated user must be in the admin role.<br />

Resource Configuration<br />

A <strong>Java</strong>Server Faces application usually includes an XML file that configures resources for the<br />

application. <strong>The</strong>se resources include <strong>Java</strong>Beans components, navigation rules, and others.<br />

Two of the resources configured for the <strong>Java</strong>Server Faces version of the Coffee Break server are<br />

the CheckoutForm bean and navigation rules for the orderForm page:<br />

<br />

checkoutFormBean<br />

<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!