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.

setting and reading cookies in vaadin 7

9 years ago Jun 08, 2012 10:59pm
Leif Åstrand
9 years ago Jun 09, 2012 11:47am
9 years ago Jun 09, 2012 6:15pm
Leif Åstrand
9 years ago Jun 10, 2012 10:56am
9 years ago Jun 11, 2012 3:46am
Fabiano Bonin
9 years ago Oct 09, 2012 1:38pm
jian hwa chin
9 years ago Oct 10, 2012 3:39am

Hi, i'm not sure is this a right solution, but my way of doin this is to cast the VaadinRequest to VaadinServletRequest at the init when ur application start to get the cookies, otherwise you can also use VaadinService ( a static class ) to get the VaadinRequest and cast it to VaadinServletRequest and get cookies. To set cookie you can get the VaadinResponse by VaadinService and cast it to VaadinServletResponse then addcookie. By the way i'm using vaadin 7 beta3 ).

Cookie[] cookies = ((VaadinServletRequest)VaadinService.getCurrentRequest()).getCookies();


Fabiano Bonin
9 years ago Jan 15, 2013 12:16pm
William McKibben
9 years ago Feb 25, 2013 4:54pm
Achim Hilwers
9 years ago Mar 04, 2013 9:13pm

I also tried to set the cookie the way it's described in this thread but it didn't work - neither in the init() method nor outside of it.

I ended up setting it via JavaScript:

Page.getCurrent().getJavaScript().execute(String.format("document.cookie = '%s=%s; expires=%s;';", loginCookieName, userName, getCookieLifeTime()));