Search code examples
javavaadinsession-variables

Vaadin 14 session-local objects


I have a Vaadin 14 application with multiple views (but no UI). I need store an object per user that is accessible in all the user's views. What is best way to implement this?


Solution

  • You can use VaadinSession.getCurrent().setAttribute(key, value); to store an object in the current VaadinSession. You can use either a String or a Class<T> key. The object will be available through VaadinSession.getCurrent().getAttribute(key) and it will be accessible from all browser tabs that are connected to the same session.