com.vaadin.addon.touchkit.extensions
Class LocalStorage

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.server.AbstractExtension
          extended by com.vaadin.addon.touchkit.extensions.LocalStorage
All Implemented Interfaces:
com.vaadin.event.MethodEventSource, com.vaadin.server.ClientConnector, com.vaadin.server.Extension, com.vaadin.shared.Connector, Serializable

public class LocalStorage
extends com.vaadin.server.AbstractExtension

A server side proxy for the browser's HTML5 local storage. Local storage is a persistent string-string map provided by modern browsers. Using this extension, server side code can access that map.

Local storage can be used bit like traditional cookies to store data on the browser, but with LocalStorage one can store much larger data and the stored data is not transferred in each HTTP request. Also if you have hybrid client-server application, you can use this class to easily fetch date stored by your client side module.

For more details about HTML 5 storage see Storage.

To save a value in browser use put(String, String) method.

As the values are behind network, retrieving a value must be done using asynchronous AP. E.g. like this:

LocalStorage.detectValue("myproperty",
        new LocalStorageCallback() {
            public void onSuccess(String value) {
                Notification.show("Value received:" + value);
            }

            public void onFailure(FailureEvent error) {
                Notification.show("Value retrieval failed: " + error.getMessage());
            }
        });
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
com.vaadin.server.ClientConnector.AttachEvent, com.vaadin.server.ClientConnector.AttachListener, com.vaadin.server.ClientConnector.ConnectorErrorEvent, com.vaadin.server.ClientConnector.DetachEvent, com.vaadin.server.ClientConnector.DetachListener
 
Method Summary
static void detectValue(String key, LocalStorageCallback callback)
          Detects the value of the given key in the client side HTML5 storage.
static LocalStorage get()
          Returns a local storage proxy bound to the currently active UI (detected via a thread local).
 void get(String key, LocalStorageCallback callback)
          Detects the value of the given key in the client side HTML5 storage.
static LocalStorage get(com.vaadin.ui.UI ui)
          Returns a local storage proxy bound to the given UI.
 void put(String key, String value)
          Stores a given key-value pair in the browser's local storage.
 void put(String key, String value, LocalStorageCallback callback)
          Stores a given key-value pair in the browser's local storage.
 
Methods inherited from class com.vaadin.server.AbstractExtension
extend, getParent, getSupportedParentType, remove, setParent
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, attach, beforeClientResponse, createState, detach, encodeState, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getState, getState, getStateType, getUI, handleConnectorRequest, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 

Method Detail

detectValue

public static void detectValue(String key,
                               LocalStorageCallback callback)
Detects the value of the given key in the client side HTML5 storage. The value is detected asynchronously, as the value detection requires a client server round trip.

This method uses thread local to get the currently active UI.

See Also:
get(String, LocalStorageCallback)

get

public static LocalStorage get()
Returns a local storage proxy bound to the currently active UI (detected via a thread local).

Returns:
an existing or newly created instance for the currently active UI

get

public static LocalStorage get(com.vaadin.ui.UI ui)
Returns a local storage proxy bound to the given UI.

Parameters:
ui - the UI to bind to.
Returns:
A LocalStorage extension bound to the given UI. If an extension is not yet applied, a new one is created and applied to the UI.

get

public void get(String key,
                LocalStorageCallback callback)
Detects the value of the given key in the client side HTML5 storage. The value is detected asynchronously, as the value detection requires a client server round trip.

Parameters:
callback - The LocalStorageCallback called when the value is available.

put

public void put(String key,
                String value)
Stores a given key-value pair in the browser's local storage. Any previous value is overridden.

Note that if you wish to be sure that the value is persisted properly, you can use put(String, String, LocalStorageCallback).

Parameters:
key - The key
value - The value for the key

put

public void put(String key,
                String value,
                LocalStorageCallback callback)
Stores a given key-value pair in the browser's local storage. Any previous value is overridden.

The callback given as parameter is notified if local storage access succeeded or failed.

Parameters:
key - The key
value - The value for the key
callback - A LocalStorageCallback to notify of success or failure.


Copyright © 2014 Vaadin Ltd. All rights reserved.