CDI events
CDI provides event handling facilities. Events allow loosely-coupled communication between different CDI beans. A CDI bean can fire an event, then one or more event listeners handle the event.
Firing CDI events
The following example is a new version of the CustomerInfoController
class we discussed in the previous section. The class has been modified to fire an event every time the user navigates to a new page:
package net.ensode.javaee8book.cdievents.controller;
import java.io.Serializable;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.inject.Named;
import net.ensode.javaee8book.cdievents.event.NavigationInfo;
import net.ensode.javaee8book.cdievents.model.Customer;
@Named
@RequestScoped
public class CustomerInfoController implements Serializable {
@Inject
private Conversation conversation;
@Inject
private Customer customer...