Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

CDIUI + CDI-helpers with CDI events

Franz Schoning
7 years ago Oct 18, 2015 8:01pm
Franz Schoning
7 years ago Oct 24, 2015 6:09pm
Petrus Viljoen
7 years ago Oct 26, 2015 12:24pm

Warning I'm not an expert in cdi, but here goes.

CDIView is @ViewScoped, the observer view is not in the same scope as the one that fires the event.

In particular

if the observer method is non-static, the container must:

Obtain a contextual instance of the bean which declares the observer method according to Contextual instance of a bean. If this observer method is a conditional observer method, obtain the contextual instance that already exists, only if the scope of the bean that declares the observer method is currently active, without creating a new contextual instance.

So you are creating an instance of the Observer view for the same scope as the event originator so that cdi can call the observer method on the contextual instance. There might be some cdi magic tricks with qualifiers to change the behaviour, but I simply don't know the spec well enough to pull one out of the hat.

In a geniric case it might be better to use the classic Listener/Event Pattern implementation to comunicate between the views. 
If you have only one of each view in the ui ( as is the case with CDIViews usually ) you could probably observe the event in the UI and delegate it from there to the observer view.