Directory

← Back

BrowserStorage Add-On for Vaadin

BrowserStorage allows access to the LocalStorage and SessionStorage objects of your user's browser from server-side Vaadin code

Author

Rating

Popularity

100+

Vaadin BrowserStorage Add-on

Adds server-side logic and a JavaScript file to allow usage of local and session storage on the client's browser from server-side Vaadin code.

This add-on should be forward-compatible up to Vaadin 23 and 24. Tested working with Vaadin 24.

Usage

The API for SessionStorage and LocalStorage are identical, and have been mapped to the Storage object API as returning completable futures, with the addition of a "contains key" function to potentially save on bandwidth, as follows:

CompletableFuture<Boolean> containsKey(String key);
CompletableFuture<String> getItem(String key);
CompletableFuture<Boolean> setItem(String key, String value);
CompletableFuture<Boolean> removeItem(String key);
CompletableFuture<Boolean> clear();

The returned boolean for setItem, removeItem and clear can safely be ignored for now; it is reserved for future use.

To access SessionStorage or LocalStorage, create an instance of them:

LocalStorage localStorage = new LocalStorage();
localStorage.setItem("foo", "bar");

Because the objects need to bind to a specific UI. In complex codebases, you may want to use the explicit constructor:

UI myUI = UI.getCurrent();
LocalStorage localStorage = new LocalStorage(myUI);
localStorage.setItem("foo", "bar");

The above examples are equivalent - the default constructor uses UI.getCurrent() internally to store a UI reference.

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Released
2022-04-19
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 14+
Browser
Firefox
Opera
Safari
Google Chrome
iOS Browser
Android Browser
Microsoft Edge

BrowserStorage Add-On for Vaadin - Vaadin Add-on Directory

BrowserStorage allows access to the LocalStorage and SessionStorage objects of your user's browser from server-side Vaadin code BrowserStorage Add-On for Vaadin - Vaadin Add-on Directory
# Vaadin BrowserStorage Add-on Adds server-side logic and a JavaScript file to allow usage of local and session storage on the client's browser from server-side Vaadin code. This add-on should be forward-compatible up to Vaadin 23 and 24. Tested working with Vaadin 24. ## Usage The API for SessionStorage and LocalStorage are identical, and have been mapped to the Storage object API as returning completable futures, with the addition of a "contains key" function to potentially save on bandwidth, as follows: ```java CompletableFuture containsKey(String key); CompletableFuture getItem(String key); CompletableFuture setItem(String key, String value); CompletableFuture removeItem(String key); CompletableFuture clear(); ``` The returned boolean for `setItem`, `removeItem` and `clear` can safely be ignored for now; it is reserved for future use. To access `SessionStorage` or `LocalStorage`, create an instance of them: ```java LocalStorage localStorage = new LocalStorage(); localStorage.setItem("foo", "bar"); ``` Because the objects need to bind to a specific UI. In complex codebases, you may want to use the explicit constructor: ```java UI myUI = UI.getCurrent(); LocalStorage localStorage = new LocalStorage(myUI); localStorage.setItem("foo", "bar"); ``` The above examples are equivalent - the default constructor uses UI.getCurrent() internally to store a UI reference.
Online