Java Reference
In-Depth Information
mentation may vary at runtime, or if the object requires some custom initialization
that is not to be performed in the constructor.
It can be used to provide any kind of concrete class implementation; however, it
is especially useful to inject Java EE resources into your application.
One advantage of using a @Producer annotation for the getSeats method is that
its objects can be exposed directly via JSF Expression Language ( EL ), as we will
see in a minute.
Finally, another feature of CDI that was unleashed in this example is the observer .
Observers, just like the name suggests, can be used to observe objects. An observer
method is notified whenever an object is created, removed, or updated. In our ex-
ample, it allows the list of seats to be refreshed whenever they are needed.
Note
To be precise, in our example, we are using a conditional Observer which is de-
noted by the expression notifyObserver = Reception.IF_EXISTS . This
means that in practice the observer method is only called if an instance of the
component already exists. If not specified, the default option ( ALWAYS ) will be
that the observer method is always called (If an instance doesn't exist, it will be
created).
Whenever a change in our list of seats occurs, we will use the
javax.enterprise.event.Event object to notify the observer of changes. This
will be done in our Singleton Bean, which gets injected with the seat's event [1] and
notifies the observer by firing the event when a seat is booked [2] .
package
com.packtpub.as7development.chapter4.ejb;
import static javax.ejb.LockType.*;
import javax.ejb.*;import
Search WWH ::




Custom Search