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.

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

366<br />

Binding a Component Instance to a Bean Property<br />

A component instance can be bound to a bean property using a value expression with the<br />

binding attribute of the component’s tag. You usually bind a component instance rather than<br />

its value to a bean property if the bean must dynamically change the component’s attributes.<br />

Here are two tags from the bookcashier.jsp page that bind components to bean properties:<br />

<br />

<br />

<br />

<br />

<strong>The</strong> selectBooleanCheckbox tag renders a check box and binds the fanClub UISelectBoolean<br />

component to the specialOffer property of CashierBean. <strong>The</strong> outputLabel tag binds the<br />

component representing the check box’s label to the specialOfferText property of<br />

CashierBean. If the application’s locale is English, the outputLabel tag renders:<br />

I’d like to join the Duke Fan Club, free with my purchase of over $100<br />

<strong>The</strong> rendered attributes of both tags are set to false, which prevents the check box and its label<br />

from being rendered. If the customer orders more than $100 (or 100 euros) worth of books and<br />

clicks the Submit button, the submit method of CashierBean sets both components’ rendered<br />

properties to true, causing the check box and its label to be rendered.<br />

<strong>The</strong>se tags use component bindings rather than value bindings because the backing bean must<br />

dynamically set the values of the components’ rendered properties.<br />

If the tags were to use value bindings instead of component bindings, the backing bean would<br />

not have direct access to the components, and would therefore require additional code to access<br />

the components from the FacesContext instance to change the components’ rendered<br />

properties.<br />

“Writing Properties Bound to Component Instances” on page 386 explains how to write the<br />

bean properties bound to the example components and also discusses how the submit method<br />

sets the rendered properties of the components.<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!