mbauer
mbauer

Reputation: 183

CDI Event fired from MDB should not be caught in SessionScoped bean

I have a problem with a CDI Event fired from an EJB Timer.

Point is, that the save event can be fired via manual user action (e.g. fired from a CDI SessionScoped bean method). In this case, all registered observers should catch it. But if the the CDI Event fired from the Timer is caught by a SessionScoped bean (which is anyway not required), an exception is thrown that no active Context could be found.

So... how can I tell the CDI eventing mechanism that only ApplicationScoped beans should catch the event, in case it was fired by the EJB Timer ?

Upvotes: 1

Views: 193

Answers (2)

mbauer
mbauer

Reputation: 183

I found the solution.

@Observes contains the parameter "notifyObserver". If you set this to Reception.IF_EXISTS, CDI won't create a SessionScoped bean outside an HTTP Request if there is none.

So the EJB Timer fired event won't be catched by a SessionScoped bean (because it does not exist) and the manually triggered one will be catched as there is an existing instance of the SessionScoped bean.

Upvotes: 3

Kukeltje
Kukeltje

Reputation: 12337

Use qualifiers as described in this stackoverflow post: Select certain CDI event observer

(not sure it realy is a duplicate, but I think it is)

Upvotes: 0

Related Questions