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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Coffee Break Server<br />

Coffee Break Server<br />

1038<br />

<strong>The</strong> Coffee Break server uses <strong>Java</strong>Server Faces technology to build its user interface. <strong>The</strong> JSP<br />

pages use <strong>Java</strong>Server Faces UI component tags to represent widgets, such as text fields and<br />

tables. All the JSP pages use preludes and codas to achieve a common look and feel among the<br />

HTML pages, and many of the JSTL custom tags discussed in Chapter 7, “<strong>Java</strong>Server Pages<br />

Standard Tag Library.”<br />

<strong>The</strong> Coffee Break server implementation is organized along the Model-View-Controller design<br />

pattern. A FacesServlet instance (included with the <strong>Java</strong>Server Faces API) acts as the<br />

controller. It examines the request URL, creates and initializes model <strong>Java</strong>Beans components,<br />

and dispatches requests to view JSP pages. <strong>The</strong> <strong>Java</strong>Beans components contain the business<br />

logic for the application; they call the web services and perform computations on the data<br />

returned from the services. <strong>The</strong> JSP pages format the data stored in the <strong>Java</strong>Beans components.<br />

<strong>The</strong> mapping between <strong>Java</strong>Beans components and pages is summarized in Table 36–1.<br />

TABLE 36–1 Model and View Components<br />

Function JSP Page <strong>Java</strong>Beans Component<br />

Update order data orderForm ShoppingCart<br />

Update delivery and billing data checkoutForm CheckoutFormBean<br />

Display order confirmation checkoutAck OrderConfirmations<br />

JSP Pages<br />

<strong>The</strong> JSP pages are as follows:<br />

■ “<strong>The</strong> orderForm Page” on page 1038<br />

■ “<strong>The</strong> checkoutForm Page” on page 1039<br />

■ “<strong>The</strong> checkoutAck Page” on page 1040<br />

<strong>The</strong> orderForm Page<br />

orderForm displays the current contents of the shopping cart. <strong>The</strong> first time the page is<br />

requested, the quantities of all the coffees are 0 (zero). Each time the customer changes the<br />

coffee amounts and clicks the Update button, the request is posted back to orderForm.<br />

<strong>The</strong> CoffeeBreakBean bean component updates the values in the shopping cart, which are then<br />

redisplayed by orderForm. When the order is complete, the customer proceeds to the<br />

checkoutForm page by clicking the Checkout button.<br />

<strong>The</strong> table of coffees displayed on the orderForm is rendered using one of the <strong>Java</strong>Server Faces<br />

component tags, dataTable. Here is part of the dataTable tag from orderForm:<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!