JSF Tip #23 - The StateHelper API

To facilitate component developers a convenience API was introduced to make it easier to implement the state saving requirements. Access to this API is made available through UIComponent.getStateHelper().

The API defines the following methods:

            
    void add(Serializable key, Object value) 
    Object eval(Serializable key) 
    Object eval(Serializable key, Object defaultValue) 
    Object get(Serializable key) 
    Object put(Serializable key, Object value) 
    Object put(Serializable key, String mapKey, Object value) 
    Object remove(Serializable key) 
    Object remove(Serializable key, Object valueOrKey) 
        

The add method

Adds the value to an internal list keyed to by the given key.

The eval methods

Gets the value of the key if found. If not found, see if it is a EL expression. And if so evaluate it. Otherwise return null (or the default value if one was given).

The get method

Get the value for the given key (single, list or map).

The put methods

The put methods put the value for the given key in an internal map.

The remove methods

The remove methods remove the value as keyed by the key, or if a key and a valueOrKey was given remove the value from the internal map or list.

Posted December 15, 2012

Up