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.

Using cookies with WEBSOCKET_XHR

Steve Zembek
7 years ago Mar 03, 2016 9:19pm

I tried using the following example to read and write cookies in my application: https://vaadin.com/wiki/-/wiki/Main/Setting+and+reading+Cookies

I am using websockets, so I updated my transport type to WEBSOCKET_XHR, yet VaadinService.getCurrentResponse() always returns null for me. Is there a different example specific to WEBSOCKET_XHR, or something else I'm missing here?

Steve Zembek
7 years ago Mar 04, 2016 4:42pm

Using javascript to write the cookie makes it functional, I can read cookies fine with the example code found in the wiki. This works for me, but I feel like the wiki may need to be updated in some way, as it is does not seem to work still with websocket_xhr. 

Page.getCurrent().getJavaScript().execute(String.format("document.cookie = '%s=%s;';", "user", username));
Jonas Ohlsson
7 years ago Mar 16, 2016 10:31pm
Giacomo Arru
5 years ago Jul 07, 2017 7:22am