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.

#{MyBean.currentOption}<br />

In addition to binding a component’s value to a bean property, the value attribute can specify a<br />

literal value or can map the component’s data to any primitive (such as int), structure (such as<br />

an array), or collection (such as a list), independent of a <strong>Java</strong>Beans component. Table 11–8 lists<br />

some example value-binding expressions that you can use with the value attribute.<br />

TABLE 11–8 Example Value-binding Expressions<br />

Value Expression<br />

A Boolean cart.numberOfItems > 0<br />

A property initialized from a context init parameter initParam.quantity<br />

A bean property CashierBean.name<br />

Value in an array books[3]<br />

Value in a collection books["fiction"]<br />

Property of an object in an array of objects books[3].price<br />

<strong>The</strong> next two sections explain in more detail how to use the value attribute to bind a<br />

component’s value to a bean property or other external data sources and how to use the binding<br />

attribute to bind a component instance to a bean property.<br />

Binding a ComponentValue to a Property<br />

To bind a component’s value to a bean property, you specify the name of the bean and the<br />

property using the value attribute. As explained in “Backing Beans” on page 307, the value<br />

expression of the component tag’s value attribute must match the corresponding managed<br />

bean declaration in the application configuration resource file.<br />

This means that the name of the bean in the value expression must match the<br />

managed-bean-name element of the managed bean declaration up to the first period (.) in the<br />

expression. Similarly, the part of the value expression after the period must match the name<br />

specified in the corresponding property-name element in the application configuration<br />

resource file.<br />

For example, consider this managed bean configuration, which configures the ImageArea bean<br />

corresponding to the North America part of the image map on the chooselocale.jsp page of<br />

the Duke’s Bookstore application:<br />

<br />

NA <br />

model.ImageArea <br />

Binding ComponentValues and Instances to External Data Sources<br />

Chapter 11 • Using <strong>Java</strong>Server FacesTechnology in JSP Pages 363

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

Saved successfully!

Ooh no, something went wrong!