Java Reference
In-Depth Information
“Registering a Value-Change Listener on a Component” in
The Java EE 6 Tutorial: Basic
Concepts
explains how to register this listener onto a component.
Implementing Action Listeners
A
javax.faces.event.ActionListener
implementation must include a
pro-
cessAction(ActionEvent)
method. The
processAction(ActionEvent)
method processes the specified action event. The JavaServer Faces implementation in-
vokes the
processAction(ActionEvent)
method when the
ActionEvent
oc-
curs.
The Duke's Bookstore case study uses two
ActionListener
implementations,
Events for Custom Components
”
on page
119
for details on
MapBookChangeListen-
er
.
“Registering an Action Listener on a Component” in
The Java EE 6 Tutorial: Basic Con-
cepts
explains how to register this listener onto a component.
Handling Events for Custom Components
As explained in “
Implementing an Event Listener
”
on page
117
,
events are automatically
queued on standard components that fire events. A custom component, on the other hand,
must manually queue events from its
decode
method if it fires events.
“
Performing Decoding
”
on page
111
explains how to queue an event on
MapComponent
using its
decode
method. This section explains how to write the class that represents the
event of clicking on the map and how to write the method that processes this event.
As explained in “
Understanding the Facelets Page
” on page
102
,
the
actionListener
attribute of the
bookstore:map
tag points to the
MapBookChangeListener
class.
The listener class's
processAction
method processes the event of clicking the image
map. Here is the
processAction
method:
@Override
public void processAction(ActionEvent actionEvent)
throws AbortProcessingException {
AreaSelectedEvent event = (AreaSelectedEvent) actionEvent;
String current = event.getMapComponent().getCurrent();
FacesContext context = FacesContext.getCurrentInstance();
String bookId = books.get(current);
context.getExternalContext().getSessionMap().put("bookId",