background image

Registering Listeners on Components

<< convertNumber Attributes | Registering an Action Listener >>
<< convertNumber Attributes | Registering an Action Listener >>

Registering Listeners on Components

TABLE 11­6
convertNumber
Attributes
(Continued)
Attribute
Type
Description
type
String
Specifies whether the string value is parsed and formatted as
a number, currency, or percentage. If not specified, number
is used.
Registering Listeners on Components
An application developer can implement listeners as classes or as backing bean methods. If a
listener is a backing bean method, the page author references the method from either the
component's valueChangeListener attribute or its actionListener attribute. If the listener is
a class, the page author can reference the listener from either a valueChangeListener tag or an
actionListener
tag and nest the tag inside the component tag in order to register the listener
on the component.
"Referencing a Method That Handles an Action Event" on page 371
and
"Referencing a Method
That Handles a Value-change Event" on page 372
describe how a page author uses the
valueChangeListener
and actionListener attributes to reference backing bean methods that
handle events.
The Duke's Bookstore application includes a ValueChangeListener implementation class but
does not use an ActionListener implementation class. This section explains how to register
the NameChanged value-change listener and a hypothetical LocaleChange action listener
implementation on components.
"Implementing Value-Change Listeners" on page 396
explains
how to implement NameChanged.
"Implementing Action Listeners" on page 397
explains how to
implement the hypothetical LocaleChange listener.
Registering a Value-Change Listener on a Component
A page author can register a ValueChangeListener implementation on a component that
implements EditableValueHolder by nesting a valueChangeListener tag within the
component's tag on the page. The valueChangeListener tag supports two attributes:
type
: References the fully qualified class name of a ValueChangeListener implementation
binding
: References an object that implements ValueChangeListener
A page author must use one of these attributes to reference the value-change listener. The type
attribute accepts a literal or a value expression. The binding attribute only accepts a value
expression, which must point to a backing bean property that accepts and returns a
ValueChangeListener
implementation.
Following is the tag corresponding to the name component from the bookcashier.jsp page. It
uses the type attribute to reference a value-change listener:
Registering Listeners on Components
Chapter 11 · Using JavaServer Faces Technology in JSP Pages
359