-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Originally by @peholmst
When using Vaadin CDI together with server push (web sockets), you cannot access any session scoped beans from any Vaadin event listeners without getting an exception. The reason is most likely that all requests are done asynchronously when web sockets push is enabled, which in turn means that there is no session info bound to the thread that actually executes them.
Take this as an example:
#!java
@Push
@CDIUI
public class CDIAndPushTestUI extends UI {
@Inject
UserInfo userInfo;
@Override
protected void init(VaadinRequest request) {
setContent(new VerticalLayout(
new Button("Hello World", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
Notification.show(userInfo.getUser());
}
}), new Button("Hello without CDI", new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
Notification.show("Just a string");
}
})));
}
}
The UserInfo
bean is session scoped. A click on the first button will cause an exception, a click on the second button will work as expected. If the @Push
annotation is removed, both buttons will work as expected.
I consider this a major issue since session scoped beans is a powerful way of sharing session date between Vaadin UI instances. I tested it on GlassFish 3.1.2.2 with websockets turned on and the grizzly fix installed.
I don't know if this has anything to do with #12021. This problem is also present in Spring, btw.
Imported from https://dev.vaadin.com/ issue #12464