3

I need to save user preferences in the browser's local storage. How can I access localStorage from my Vaadin code?

I tried with https://vaadin.com/directory/component/clientstorage but it looks that this addon supports only vaadin 7-8 versions, and I am using version 12.

Anna Koskinen
  • 1,362
  • 3
  • 22
Cayman
  • 367
  • 1
  • 4
  • 16

1 Answers1

1

There is no server side Java API for local storage.
But you may call JavaScript on the client side to deal with it directly.
- Denis Anisimov, from a github 'ticket'

You will have to find out how to access localStorage using javascript. There are many tutorials in the net how to do that so I won't be explaining it here.

If you don't know how to add javascript to your view in Vaadin and then call it, please see here and here

kscherrer
  • 5,486
  • 2
  • 19
  • 59
  • Well, I'm aware of how to access local storage from JS but how can I execute JS code from Vaadin java code and get JS function's result? To be more precisely I need to get client preferences from local storage and hide or unhide columns in my Grid component/ – Cayman Jan 23 '19 at 13:24
  • I have no real experience in using JS in Vaadin. Sadly I cannot help you further, all I know is what's already written in the links in my answer. – kscherrer Jan 23 '19 at 14:44
  • Something like that: `UI.getCurrent().getPage().executeJs("return $0.get...", component.getElement()).then(result -> System.out.println(result.asNumber()));` – PAX Nov 02 '20 at 12:06