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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TABLE 11–6 convertNumber Attributes (Continued)<br />

Attribute Type Description<br />

type String Specifies whether the string value is parsed and formatted as<br />

a number, currency,orpercentage. If not specified, number<br />

is used.<br />

Registering Listeners on Components<br />

An application developer can implement listeners as classes or as backing bean methods. If a<br />

listener is a backing bean method, the page author references the method from either the<br />

component’s valueChangeListener attribute or its actionListener attribute. If the listener is<br />

a class, the page author can reference the listener from either a valueChangeListener tag or an<br />

actionListener tag and nest the tag inside the component tag in order to register the listener<br />

on the component.<br />

“Referencing a Method That Handles an Action Event” on page 369 and “Referencing a Method<br />

That Handles a Value-change Event” on page 370 describe how a page author uses the<br />

valueChangeListener and actionListener attributes to reference backing bean methods that<br />

handle events.<br />

<strong>The</strong> Duke’s Bookstore application includes a ValueChangeListener implementation class but<br />

does not use an ActionListener implementation class. This section explains how to register<br />

the NameChanged value-change listener and a hypothetical LocaleChange action listener<br />

implementation on components. “Implementing Value-Change Listeners” on page 394 explains<br />

how to implement NameChanged. “Implementing Action Listeners” on page 395 explains how to<br />

implement the hypothetical LocaleChange listener.<br />

Registering aValue-Change Listener on a Component<br />

A page author can register a ValueChangeListener implementation on a component that<br />

implements EditableValueHolder by nesting a valueChangeListener tag within the<br />

component’s tag on the page. <strong>The</strong> valueChangeListener tag supports two attributes:<br />

■ type: References the fully qualified class name of a ValueChangeListener implementation<br />

■ binding: References an object that implements ValueChangeListener<br />

Registering Listeners on Components<br />

A page author must use one of these attributes to reference the value-change listener. <strong>The</strong> type<br />

attribute accepts a literal or a value expression. <strong>The</strong> binding attribute only accepts a value<br />

expression, which must point to a backing bean property that accepts and returns a<br />

ValueChangeListener implementation.<br />

Following is the tag corresponding to the name component from the bookcashier.jsp page. It<br />

uses the type attribute to reference a value-change listener:<br />

Chapter 11 • Using <strong>Java</strong>Server FacesTechnology in JSP Pages 357

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!