Accessing LocalStorage from Vaadin

Fairly new to vaadin \ java, so maybe I’m just not understanding how this needs to be called. I’m using the following to import the storage components:

import com.google.gwt.storage.client.Storage;

When I try to access localStorage from an onclick with the following code:

Button loginB = new Button(“Read Storage”);
loginB.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
Storage Cart = Storage.getSessionStorageIfSupported();
new Notification(Cart.getItem(“cartinfo”)).show(Page.getCurrent());
}
});

I receive the following error:

java.lang.NoClassDefFoundError: com/google/gwt/storage/client/Storage

Can anyone point me in the right direction on how to resolve this? Is there something I’m not doing correctly? Is there something else I need to import?

You are mixing client side and server side. Your button click listener is run on the server. The GWT classes are useful on the client side (in the browser), where you can access the session storage directly.

If you just want to store some data and don’t care if it is stored in the local storage or somewhere else, store it e.g. as a field in the class containing the Button.

If you want to use the local storage, you need to send the data from the server to the client and update the local storage on the client side. See e.g. https://github.com/Artur-/devday-extending/tree/master/src/main/java/org/vaadin/artur/localstorage + https://github.com/Artur-/devday-extending/blob/master/src/main/resources/org/vaadin/artur/localstorage/localstorage.js for an example how you can create an extension for this