Java Reference
In-Depth Information
public class SeatTypeProducer implements
Serializable {
@Inject
private DataManager seatRepository;
private List<SeatType> seatTypes;
@Produces
@Named
public List<SeatType> getSeatTypes() {
return seatTypes;
}
public void
onListChanged(@Observes(notifyObserver =
Reception.IF_EXISTS) final SeatType member) {
retrieveData();
}
@PostConstruct
public void retrieveData() {
seatTypes =
seatRepository.findAllSeatTypes();
}
}
If you have gone through our example in
Chapter 4
,
Learning Context Dependency
Injection
, you will find nothing new here; as you can see, this class will merely pro-
duce a collection of
seatTypes
that are tagged as
@Named
so that they can be
accessed from
JSF EL
as well. Additionally, this class contains an
Observer
hand-
ler method (
onListChanged
), which will be fired when data in the collection is
changed.
The collection data is filled up using the
retrieveData
method (loaded the first
and only time when the class is constructed) of the
DataManager
CDI Bean. We