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());
}
});
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.