Class State

java.lang.Object
org.omnifaces.util.State

public class State extends Object
Helper class for StateHelper that uses generic type-inference to make code that uses the StateHelper slightly less verbose.
Since:
1.1
Author:
Arjan Tijms
  • Constructor Details

  • Method Details

    • get

      public <T> T get(Serializable key)
      Attempts to find a value associated with the specified key in the component's state.

      See StateHelper.eval(Serializable)

      Type Parameters:
      T - The expected return type.
      Parameters:
      key - the name of the value in component's state
      Returns:
      The value associated with the specified key.
      Throws:
      ClassCastException - When T is of wrong type.
    • get

      public <T> T get(Serializable key, Object defaultValue)
      Attempts to find a value associated with the specified key in the component's state.

      See StateHelper.eval(Serializable, Object)

      Type Parameters:
      T - The expected return type.
      Parameters:
      key - the name of the value in component's state
      defaultValue - the value to return if no value is found in the call to get()
      Returns:
      The value associated with the specified key, or the given default value if no value is found.
      Throws:
      ClassCastException - When T is of wrong type.
    • put

      public <T> T put(Serializable key, T value)
      Puts a value in the component's state and returns the previous value. Note that the previous value has to be of the same type as the value being set. If this is unwanted, use the original StateHelper.

      See StateHelper.put(Serializable, Object)

      Type Parameters:
      T - The expected value and return type.
      Parameters:
      key - The name of the value in component's state.
      value - The value to put in component's state.
      Returns:
      The previous value, if any.
      Throws:
      ClassCastException - When T is of wrong type.