|
Download
FAQ History |
|
API
Search Feedback |
Registering Listeners on Components
A page author can register a listener implementation class on a component by nesting either a
valuechangeListenertag or anactionListenertag within the component's tag on the page.An application developer can instead implement these listeners as backing bean methods. To reference these methods, a page author uses the component tag's
valueChangeListenerandactionListenerattributes, as described in Referencing a Method That Handles an ActionEvent and Referencing a Method That Handles a ValueChangeEvent.The Duke's Bookstore application includes a
ValueChangeListenerimplementation class but does not use anActionListenerimplementation class. This section explains how to register theNameChangeValueChangeListenerand a hypotheticalLocaleChangeActionListenerimplementation on components. Implementing Value-Change Listeners explains how to implementNameChange. Implementing Action Listeners explains how to implement the hypotheticalLocaleChange.Registering a ValueChangeListener on a Component
A page author can register a
ValueChangeListeneron aUIInputcomponent or a component represented by one of the subclasses ofUIInputby nesting avaluechangeListenertag within the component's tag on the page. Here is the tag corresponding to thenamecomponent from thebookcashier.jsppage:<h:inputText id="name" size="50" value="#{cashier.name}" required="true"> <f:valueChangeListener type="listeners.NameChanged" /> </h:inputText>The
typeattribute of thevalueChangeListenertag specifies the fully qualified class name of theValueChangeListenerimplementation.After this component tag is processed and local values have been validated, the component instance represented by this tag will automatically queue the
ValueChangeEventassociated with the specifiedValueChangeListenerto the component.Registering an ActionListener on a Component
A page author can register an
ActionListeneron aUICommandcomponent by nesting anactionListenertag within the component's tag on the page. Duke's Bookstore does not use anyActionListenerimplementations. Here is one of thecommandLinktags on thechooselocale.jsppage, changed to reference anActionListenerimplementation rather than a backing bean method:<h:commandLink id="NAmerica" action="bookstore"> <f:actionListener type="listeners.LocaleChange" /> </h:commandLink>The
typeattribute of theactionListenertag specifies the fully qualified class name of theActionListenerimplementation.When the component associated with this tag is activated, the component's
decodemethod (or its associatedRenderer) automatically queues theActionEventassociated with the specifiedActionListenerto the component.
|
Download
FAQ History |
|
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.