Java Reference
In-Depth Information
Observer methods may throw exceptions. If a transactional observer method throws an
exception, the exception is caught by the container. If the observer method is non-trans-
actional, the exception terminates processing of the event, and no other observer methods
for the event are called.
Firing Events
To activate an event, call the javax.enterprise.event.Event.fire method.
This method fires an event and notifies any observer methods.
In the billpayment example, a managed bean called PaymentBean fires the appro-
priate event by using information it receives from the user interface. There are actually
four event beans, two for the event object and two for the payload. The managed bean
injects the two event beans. The pay method uses a switch statement to choose which
event to fire, using new to create the payload.
Click here to view code image
@Inject
@Credit
Event<PaymentEvent> creditEvent;
@Inject
@Debit
Event<PaymentEvent> debitEvent;
private static final int DEBIT = 1;
private static final int CREDIT = 2;
private int paymentOption = DEBIT;
...
@Logged
public String pay() {
...
switch (paymentOption) {
case DEBIT:
PaymentEvent debitPayload = new PaymentEvent();
// populate payload ...
debitEvent.fire(debitPayload);
break;
case CREDIT:
PaymentEvent creditPayload = new PaymentEvent();
// populate payload ...
creditEvent.fire(creditPayload);
break;
default:
Search WWH ::




Custom Search