marlon
marlon

Reputation: 7633

When to implement a CDI Event?

When a user clicks a button on JSF, a managed bean receives the input value from front end. To process the request and respond, when should or shouldn't I implement a CDI event? For instance, to print back "Hello World" to html page after a user clicks a button on a front end JSF page, I can implement a CDI Event using event-observer model, or I can do the same thing in many other ways.

My question is, what are appropriate scenarios to implement a request-process operation as a CDI event? Thanks.

Upvotes: 0

Views: 73

Answers (1)

Petr Mensik
Petr Mensik

Reputation: 27496

Usually you want to use events when a request from user will affect multiple parts of application. Let's say user changed some settings it his profile and they are multiple components affected by this change so you can fire up an single event and all these components will be able to handle the configuration change.

Another argument for using events is to decouple your components so there are less dependencies in your application.

So for your example, events are probably overkill for such simple operation as printing Hello world.

Upvotes: 1

Related Questions