background image

Properties Bound to Converters

<< Properties Bound to Component Instances | Performing Localization >>
<< Properties Bound to Component Instances | Performing Localization >>

Properties Bound to Converters

See
"Backing Beans" on page 309
for more general information on component binding.
See
"Referencing a Method That Performs Navigation" on page 371
for information on how to
reference a backing bean method that performs navigation when a button is clicked.
See
"Writing a Method to Handle Navigation" on page 404
for more information on writing
backing bean methods that handle navigation.
Writing Properties Bound to Converters, Listeners, or
Validators
All of the standard converter, listener, and validator tags that are included with JavaServer Faces
technology support binding attributes that allow page authors to bind converter, listener, or
validator implementations to backing bean properties.
The following example from
"Binding Converters, Listeners, and Validators to Backing Bean
Properties" on page 369
shows a standard convertDateTime tag using a value expression with
its binding attribute to bind the DateTimeConverter instance to the convertDate property of
LoginBean
:
<h:inputText value=
"#{LoginBean.birthDate}">
<f:convertDateTime binding=
"#{LoginBean.convertDate}" />
</h:inputText>
The convertDate property must therefore accept and return a DateTimeConverter object, as
shown here:
private DateTimeConverter convertDate;
public DateTimeConverter getConvertDate() {
...
return convertDate;
{
public void setConvertDate(DateTimeConverter convertDate) {
convertDate.setPattern(
"EEEEEEEE, MMM dd, yyyy");
this.convertDate = convertDate;
}
Because the converter is bound to a backing bean property, the backing bean property is able to
modify the attributes of the converter or add new functionality to it. In the case of the preceding
example, the property sets the date pattern that the converter will use to parse the user's input
into a Date object.
The backing bean properties that are bound to validator or listener implementations are written
in the same way and have the same general purpose.
Writing Bean Properties
Chapter 12 · Developing with JavaServer Faces Technology
389