About
Listeners are used to listen to the events happening in the page and perform actions as defined.
An application developer can implement listeners as:
- or as managed bean methods.
Articles Related
Referencing a Method That Handles
an Action Event
If a component on your page generates an action event, and if that event is handled by a managed bean method, you refer to the method by using the component’s actionListener attribute.
The following example shows how such a method could be referenced:
<h:commandLink id="Duke" action="bookstore"
actionListener="#{actionBean.chooseBookFromLink}">
The actionListener attribute of this component tag references the chooseBookFromLink method using a method expression. The chooseBookFromLink method handles the event when the user clicks the hyperlink rendered by this component.
a Value-Change Event
If you want a component on your page to generate a value-change event and you want that event to be handled by a managed bean method instead of a ValueChangeListener implementation, you refer to the method by using the component’s valueChangeListener attribute:
<h:inputText id="name"
size="30"
value="#{cashier.name}"
required="true"
valueChangeListener="#{cashier.processValueChange}" />
</h:inputText>
The valueChangeListener attribute of this component tag references the processValueChange method of CashierBean by using a method expression. The processValueChange method handles the event of a user entering a name in the input field rendered by this component.