Java Reference
In-Depth Information
The
h:selectBooleanCheckbox
tag renders a check box and binds the
fanClub
UISelectBoolean
component to the
specialOffer
property of the
cashier
bean. The
h:outputLabel
tag binds the component representing the check box's label
to the
specialOfferText
property of the
cashier
bean. If the application's locale
is English, the
h:outputLabel
tag renders:
I'd like to join the Duke Fan Club, free with my purchase of over
$100
The
rendered
attributes of both tags are set to
false
, to prevent the check box and
its label from being rendered. If the customer makes a large order and clicks the Submit
button, the
submit
method of
CashierBean
sets both components'
rendered
prop-
erties to
true
, causing the check box and its label to be rendered.
These tags use component bindings rather than value bindings, because the managed bean
must dynamically set the values of the components'
rendered
properties.
If the tags were to use value bindings instead of component bindings, the managed bean
would not have direct access to the components, and would therefore require additional
code to access the components from the
FacesContext
instance to change the com-
ponents'
rendered
properties.
“Writing Properties Bound to Component Instances” in
The Java EE 6 Tutorial: Basic
Concepts
explains how to write the bean properties bound to the example components.
Binding
Converters,
Listeners,
and
Validators
to
Managed
Bean
Properties
As described in “Adding Components to a Page Using HTML Tags” in
The Java EE 6
Tutorial: Basic Concepts
, a page author can bind converter, listener, and validator imple-
mentations to managed bean properties using the
binding
attributes of the tags that are
used to register the implementations on components.
This technique has similar advantages to binding component instances to managed bean
properties, as described in “
Binding Component Values and Instances to Managed Bean
Properties
”
on page
133
.
In particular, binding a converter, listener, or validator imple-
mentation to a managed bean property yields the following benefits:
• The managed bean can instantiate the implementation instead of allowing the page
author to do so.
• The managed bean can programmatically modify the attributes of the implement-
ation. In the case of a custom implementation, the only other way to modify the