HTML5 Local/ Session Storage


I found this addon for accessing local/ session storage from browser… The dependency is fine and compiles but doesnt work. I notice later the doc page indicates support for vaadin 8.

Is there a newer version uplifted for vaadin 14? If not, any other alternatives for the same function?



It’s easier to call javascript function and retrieve data. So you can use directly the javascript API. Here you have an example of javascript calls:

That can be translated into Java calls:

public class LocalStorageView extends VerticalLayout {

    private int i = 0;
    public LocalStorageView(@Autowired MessageBean bean) {

        Button setItemButton = new Button("setItem");
        setItemButton.addClickListener(buttonClickEvent -> setItem());

        Button retrieveItemButton = new Button("retrieveItem");
        retrieveItemButton.addClickListener(buttonClickEvent -> retrieveItem());
        add(setItemButton, retrieveItemButton);

    private void setItem() {
        getElement().executeJs("debugger; window.localStorage.setItem($0, $1);", "name", "Obaseki Nosa" + i++);

    private void retrieveItem() {
        getElement().executeJs("debugger;return window.localStorage.getItem($0);", "name")
                .then(String.class, result ->"name is "+ result));

(Edit: I think it requires Vaadin 14.2 minimum or perhaps only 14.1)