Reputation: 21
We are using Vaadin 23 (23.0.9) with vaadin-cdi (14.0.0) and are having problems with conditional observers in @RouteScoped components (like it is described in the tutorial):
@RouteScoped
public class ScopedComponent extends Div {
private void onMessage(
@Observes(notifyObserver = IF_EXISTS)
MessageEvent message) {
setText(message.getText());
}
}
We are running on Tomcat 9 and use Weld (3.1.9.Final) as our CDI implementation. Our current problem is that we get the following exception when firing an event that is observed in a @RouteScoped component:
java.lang.IllegalStateException: Route owner 'class XXX' instance is not available in the active navigation components chain: the scope defined by the bean 'YYY' doesn't exist.
We believe that the problem are the changes implemented in Vaadin CDI 13.0.0 (https://github.com/vaadin/cdi/releases/tag/13.0.0):
Trying to use @RouteScope when there is no active route component present is not allowed.
In the Weld implementation we are using, the method getReceiverIfExists calls the method getContextualStorage() in class RouteScopedContext. And getReceiverIfExists is called before the reception of the observer is considered. Therefore all classes that have an observer on the event are trying to be received and since not all @RouteScoped classes are in the current navigation chain, the above mentioned error is thrown.
Object receiver = getReceiverIfExists(null); //this is where the exception is thrown
if (receiver == null && reception != Reception.IF_EXISTS) {
// creational context is created only if we need it for obtaining receiver
// ObserverInvocationStrategy takes care of creating CC for parameters, if needed
creationalContext = beanManager.createCreationalContext(declaringBean);
receiver = getReceiverIfExists(creationalContext);
}
if (receiver != null) {
sendEvent(event, receiver, creationalContext);
}
We are not quite sure, what we are doing wrong or what we could do differently. Are we using the correct versions vaadin-cdi and Weld?
Upvotes: 1
Views: 143
Reputation: 21
This is currently a bug in vaadin-cdi (version 14.0.0): https://github.com/vaadin/cdi/issues/390
A bugfix is already merged: https://github.com/vaadin/cdi/pull/393
Upvotes: 1