Java Reference
In-Depth Information
The example also defines an interceptor that is set on a class and on two methods of an-
other class.
The PaymentEvent Event Class
The event class, event.PaymentEvent , is a simple bean class that contains a no-ar-
gument constructor. It also has a toString method and getter and setter methods for the
payload components: a String for the payment type, a BigDecimal for the payment
amount, and a Date for the timestamp.
Click here to view code image
public class PaymentEvent implements Serializable {
...
public String paymentType;
public BigDecimal value;
public Date datetime;
public PaymentEvent() {
}
@Override
public String toString() {
return this.paymentType
+ " = $" + this.value.toString()
+ " at " + this.datetime.toString();
}
...
The event class is a simple bean that is instantiated by the managed bean using new and
then populated. For this reason, the CDI container cannot intercept the creation of the
bean, and hence it cannot allow interception of its getter and setter methods.
The PaymentHandler Event Listener
The event listener, listener.PaymentHandler , contains two observer methods,
one for each of the two event types:
Click here to view code image
@Logged
@SessionScoped
public class PaymentHandler implements Serializable {
...
public void creditPayment(@Observes @Credit PaymentEvent event)
Search WWH ::




Custom Search