Package com.oorian.html.js.storage
Class StorageEvent
java.lang.Object
com.oorian.messaging.events.Event<StorageListener>
com.oorian.messaging.events.client.ClientEvent<StorageListener>
com.oorian.html.js.storage.StorageEvent
Event fired when a value has been retrieved from browser storage.
This event is dispatched to the element that initiated the storage read request.
Usage:
public void onEvent(StorageEvent event) {
if (event.hasValue()) {
String username = event.getValue();
// Use the retrieved value
} else {
// Key not found in storage
}
}
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionStorageEvent(String key, String value, String storageType) Constructs a StorageEvent with the retrieved key/value pair. -
Method Summary
Modifier and TypeMethodDescriptionvoiddispatchTo(StorageListener listener) Dispatches this event to the specified listener.getKey()Returns the storage key that was requested.Returns the type of storage that was accessed.getValue()Returns the value retrieved from storage.booleanhasValue()Checks if a value was found for the requested key.booleanChecks if this event is from localStorage.booleanChecks if this event is from sessionStorage.toString()Methods inherited from class com.oorian.messaging.events.client.ClientEvent
getSource, getTarget, setSource, setTarget
-
Field Details
-
LOCAL
Storage type constant for localStorage.- See Also:
-
SESSION
Storage type constant for sessionStorage.- See Also:
-
-
Constructor Details
-
StorageEvent
Constructs a StorageEvent with the retrieved key/value pair.- Parameters:
key- The storage key that was requested.value- The value retrieved from storage, or null if not found.storageType- The type of storage ("local" or "session").
-
-
Method Details
-
getKey
Returns the storage key that was requested.- Returns:
- The storage key.
-
getValue
Returns the value retrieved from storage.- Returns:
- The value, or null if the key was not found.
-
getStorageType
Returns the type of storage that was accessed.- Returns:
- "local" for localStorage, "session" for sessionStorage.
-
hasValue
public boolean hasValue()Checks if a value was found for the requested key.- Returns:
trueif a value was found,falseif the key was not in storage.
-
isLocalStorage
public boolean isLocalStorage()Checks if this event is from localStorage.- Returns:
trueif the value was from localStorage.
-
isSessionStorage
public boolean isSessionStorage()Checks if this event is from sessionStorage.- Returns:
trueif the value was from sessionStorage.
-
dispatchTo
Description copied from class:EventDispatches this event to the specified listener.Subclasses implement this method to call the appropriate handler method on the listener interface.
- Specified by:
dispatchToin classEvent<StorageListener>- Parameters:
listener- the listener to dispatch this event to
-
toString
-