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 />

386<br />

Writing Properties Bound to Component Instances<br />

A property bound to a component instance returns and accepts a component instance rather<br />

than a component value. Here are the tags described in “Binding a Component Instance to a<br />

Bean Property” on page 366 that bind components to backing bean properties:<br />

<br />

<br />

<br />

<br />

As “Binding a Component Instance to a Bean Property” on page 366 explains, the<br />

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 />

fanClubLabel component (which represents the check box’s label) to the specialOfferText<br />

property of CashierBean. If the user 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 label to display when the page is re-rendered.<br />

Because the components corresponding to the example tags are bound to the backing bean<br />

properties, these properties must match the components’ types. This means that the<br />

specialOfferText property must be of UIOutput type, and the specialOffer property must<br />

be of UISelectBoolean type:<br />

UIOutput specialOfferText = null;<br />

public UIOutput getSpecialOfferText() {<br />

return this.specialOfferText;<br />

}<br />

public void setSpecialOfferText(UIOutput specialOfferText) {<br />

this.specialOfferText = specialOfferText;<br />

}<br />

UISelectBoolean specialOffer = null;<br />

public UISelectBoolean getSpecialOffer() {<br />

return this.specialOffer;<br />

}<br />

public void setSpecialOffer(UISelectBoolean specialOffer) {<br />

this.specialOffer = specialOffer;<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!