Class StorageEvent


public class StorageEvent extends ClientEvent<StorageListener>
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 Details

  • Constructor Details

    • StorageEvent

      public StorageEvent(String key, String value, String storageType)
      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

      public String getKey()
      Returns the storage key that was requested.
      Returns:
      The storage key.
    • getValue

      public String getValue()
      Returns the value retrieved from storage.
      Returns:
      The value, or null if the key was not found.
    • getStorageType

      public String 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:
      true if a value was found, false if the key was not in storage.
    • isLocalStorage

      public boolean isLocalStorage()
      Checks if this event is from localStorage.
      Returns:
      true if the value was from localStorage.
    • isSessionStorage

      public boolean isSessionStorage()
      Checks if this event is from sessionStorage.
      Returns:
      true if the value was from sessionStorage.
    • dispatchTo

      public void dispatchTo(StorageListener listener)
      Description copied from class: Event
      Dispatches this event to the specified listener.

      Subclasses implement this method to call the appropriate handler method on the listener interface.

      Specified by:
      dispatchTo in class Event<StorageListener>
      Parameters:
      listener - the listener to dispatch this event to
    • toString

      public String toString()
      Overrides:
      toString in class Object