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.

Writing Bean Properties<br />

380<br />

}<br />

public void setShipDate(Date shipDate) {<br />

this.shipDate = shipDate;<br />

}<br />

See “Binding Component Values and Instances to External Data Sources” on page 362 for more<br />

information on applying a Converter implementation.<br />

UIData Properties<br />

UIData components must be bound to one of the types listed in Table 12–1. <strong>The</strong> UIData<br />

component from the bookshowcart.jsp page of the Duke’s Bookstore example is discussed in<br />

the section “Using Data-Bound Table Components” on page 335. Here is part of the start tag of<br />

dataTable from that section:<br />

<br />

<strong>The</strong> value expression points to the items property of the ShoppingCart bean. <strong>The</strong><br />

ShoppingCart bean maintains a map of ShoppingCartItem beans.<br />

<strong>The</strong> getItems method from ShoppingCart populates a List with ShoppingCartItem instances<br />

that are saved in the items map from when the customer adds books to the cart:<br />

public synchronized List getItems() {<br />

List results = new ArrayList();<br />

results.addAll(this.items.values());<br />

return results;<br />

}<br />

All the components contained in the UIData component are bound to the properties of the<br />

ShoppingCart bean that is bound to the entire UIData component. For example, here is the<br />

outputText tag that displays the book title in the table:<br />

<br />

<br />

<br />

<strong>The</strong> book title is actually a hyperlink to the bookdetails.jsp page. <strong>The</strong> outputText tag uses<br />

the value expression #{item.item.title} to bind its UIOutput component to the title<br />

property of the Book bean. <strong>The</strong> first item in the expression is the ShoppingCartItem instance<br />

that the dataTable tag is referencing while rendering the current row. <strong>The</strong> second item in the<br />

expression refers to the item property of ShoppingCartItem, which returns a Book bean. <strong>The</strong><br />

title part of the expression refers to the title property of Book. <strong>The</strong> value of the UIOutput<br />

component corresponding to this tag is bound to the title property of the Book bean:<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!