Java Reference
In-Depth Information
Let's start with the
addItem
method in
ItemController
. The relevant code for firing
events is shown in the following listing.
Listing 12.14.
ItemController
and firing events
In this listing the
ItemController
broadcasts new items. The event object is first injec-
ted into the bean . It's qualified with the
@NewItem
qualifier so that you can target
listeners who are specifically interested in a new item that has just been listed. The event
object itself makes use of Java's Generics to ensure that you only call
fire
with the right
type of object. Firing is relatively straightforward—you just call
fire
on the event object,
passing in the item
. The code for processing an event is shown in the next listing.
Listing 12.15.
LandingController
updating its cache on a
NewItem
event