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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Registering Listeners on Components<br />

358<br />

<br />

<br />

<br />

<strong>The</strong> type attribute specifies the custom NameChanged listener as the ValueChangeListener<br />

implementation to register on the name component.<br />

After this component tag is processed and local values have been validated, its corresponding<br />

component instance will queue the ValueChangeEvent associated with the specified<br />

ValueChangeListener to the component.<br />

<strong>The</strong> binding attribute is used to bind a ValueChangeListener implementation to a backing<br />

bean property. It works in a similar way to the binding attribute supported by the standard<br />

converter tags. “Binding Component Values and Instances to External Data Sources” on<br />

page 362 explains more about binding listeners to backing bean properties.<br />

Registering an Action Listener on a Component<br />

A page author can register an ActionListener implementation on a UICommand component by<br />

nesting an actionListener tag within the component’s tag on the page. Similarly to the<br />

valueChangeListener tag, the actionListener tag supports both the type and binding<br />

attributes. A page author must use one of these attributes to reference the action listener.<br />

Duke’s Bookstore does not use any ActionListener implementations. Here is one of the<br />

commandLink tags on the chooselocale.jsp page, changed to reference an ActionListener<br />

implementation rather than a backing bean method:<br />

<br />

<br />

<br />

<strong>The</strong> type attribute of the actionListener tag specifies the fully qualified class name of the<br />

ActionListener implementation. Similarly to the valueChangeListener tag, the<br />

actionListener tag also supports the binding attribute. “Binding Converters, Listeners, and<br />

Validators to Backing Bean Properties” on page 367 explains more about how to bind listeners<br />

to backing bean properties.<br />

When this tag’s component is activated, the component’s decode method (or its associated<br />

Renderer) automatically queues the ActionEvent implementation associated with the specified<br />

ActionListener implementation onto the component.<br />

In addition to the actionListener tag that allows you register a custom listener onto a<br />

component, the core tag library includes the setPropertyActionListener tag. You use this tag<br />

to register a special action listener onto the ActionSource instance associated with a<br />

component. When the component is activated, the listener will store the object referenced by<br />

the tag’s value attribute into the object referenced by the tag’s target attribute.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

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

Saved successfully!

Ooh no, something went wrong!