Listening to the event

Now, the application has to specify a component that listens to this event and executes some further logic. We need to define an event listener. We can do this as part of a new managed bean, such as PersonCreationEventListener. This managed bean will define an observer function. An observer function comes with the signature void. It is important to specify a parameter, which is actually the event that we fire. The event is annotated with the @Observes annotation. We then execute some logic on the event parameter of the event listener, as follows:

class PersonCreationEventListener {
fun onPersonCreation(@Observes event: PersonCreationEvent) {
println("new person created with id " + event.identifier)
}
}
..................Content has been hidden....................

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