Events

CDI supports events. A bean can send an event representable by a simple POJO and another bean can receive it and execute the next operation tied to it. An event is a good manner to decoupling of the code because it works with transversal classes. The Event interface is used to inject the events with any bean we want.

Here's a simple event object:

public class Bill {
...
}

It can be injected in any bean:

@Inject
private Event<Bill> billEvent;

It can also be started:

Bill bill = new Bill();
bill.setId(0);
bill.setTitle("ticket for the concert of Franco Battiato");
billEvent.fire(bill);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.253.152