background image

Properties Bound to Component Instances

<< Initializing optionsGroup | Properties Bound to Converters >>
<< Initializing optionsGroup | Properties Bound to Converters >>

Properties Bound to Component Instances

Writing Properties Bound to Component Instances
A property bound to a component instance returns and accepts a component instance rather
than a component value. Here are the tags described in
"Binding a Component Instance to a
Bean Property" on page 368
that bind components to backing bean properties:
<h:selectBooleanCheckbox
id=
"fanClub"
rendered=
"false"
binding=
"#{cashier.specialOffer}" />
<h:outputLabel for=
"fanClub"
rendered=
"false"
binding=
"#{cashier.specialOfferText}"
>
<h:outputText id=
"fanClubLabel"
value=
"#{bundle.DukeFanClub}" />
</h:outputLabel>
As
"Binding a Component Instance to a Bean Property" on page 368
explains, the
selectBooleanCheckbox
tag renders a check box and binds the fanClub UISelectBoolean
component to the specialOffer property of CashierBean. The outputLabel tag binds the
fanClubLabel
component (which represents the check box's label) to the specialOfferText
property of CashierBean. If the user orders more than $100 (or 100 euros) worth of books and
clicks the Submit button, the submit method of CashierBean sets both components' rendered
properties to true, causing the check box and label to display when the page is re-rendered.
Because the components corresponding to the example tags are bound to the backing bean
properties, these properties must match the components' types. This means that the
specialOfferText
property must be of UIOutput type, and the specialOffer property must
be of UISelectBoolean type:
UIOutput specialOfferText = null;
public UIOutput getSpecialOfferText() {
return this.specialOfferText;
}
public void setSpecialOfferText(UIOutput specialOfferText) {
this.specialOfferText = specialOfferText;
}
UISelectBoolean specialOffer = null;
public UISelectBoolean getSpecialOffer() {
return this.specialOffer;
}
public void setSpecialOffer(UISelectBoolean specialOffer) {
this.specialOffer = specialOffer;
}
Writing Bean Properties
The Java EE 5 Tutorial · September 2007
388