org.apache.myfaces.trinidad.util

## Class RequestStateMap

- java.lang.Object
- - java.util.AbstractMap<K,V>
  - - java.util.HashMap<String,Object>
    - - org.apache.myfaces.trinidad.util.RequestStateMap

- All Implemented Interfaces:
    Serializable, Cloneable, Map<String,Object>

      @ExcludeFromManagedRequestScope
      public class RequestStateMap
      extends HashMap<String,Object>

  This object provides a map that is primarily used to enforce a consistent contract for "state" information in both a portal environment and a servlet environment. In a portal environment, request-scope attributes are not necessarily "saved" between processAction and render. According to the JSF Portlet Bridge Spec, a request-scope attribute may hang around from a single processAction to multiple render requests unless it is excluded. Of course, excluding the object from the managed request scope will suffer from the problem of the request scope going away BETWEEN action and render.

  This class will save an attribute in a processAction portion of the request, will preserve it on the session, and will read it on the first render following the action. This allows attributes to be reliably exchanged from action to render without having to worry about subsequent renders inheriting the same state. This is useful for storing things like "ppr" data and such when a subsequent render may be expected to render the entire page.

  In a servlet environment, this class is the same as the request scope.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.util.AbstractMap

      `AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static RequestStateMap` | `getInstance(javax.faces.context.ExternalContext ec)` Returns an instance of the RequestStateMap.
    `static RequestStateMap` | `getInstance(javax.servlet.ServletRequest req)` Returns an instance of the RequestStateMap.
    `void` | `saveState(javax.faces.context.ExternalContext ec)` Saves the current state to the session.

    - ### Methods inherited from class java.util.HashMap

      `clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values`

    - ### Methods inherited from class java.util.AbstractMap

      `equals, hashCode, toString`

    - ### Methods inherited from class java.lang.Object

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Map

      `equals, hashCode`

- - ### Method Detail

    - #### getInstance

          public static RequestStateMap getInstance(javax.servlet.ServletRequest req)

      Returns an instance of the RequestStateMap. If one is not already present on the request, it will create a new one. This version of the getInstance DOES NOT attempt to restore the map from the session because such an action is only valid in a PortletEnvironment which should not have a ServletRequest. This method is provided for the convenience of getting access to the class from the filter.
      Parameters:
        `req` - a servletRequest
      Returns:
        the RequestStateMap for this servletRequest

    - #### getInstance

          public static RequestStateMap getInstance(javax.faces.context.ExternalContext ec)

      Returns an instance of the RequestStateMap. If the RequestStateMap is not present, this class will attempt to find a version that was saved from `saveState(ExternalContext)`. If no state was saved, then it will create a new map and return it.

      Please keep in mind that regardless of whether a map was already present on the request or not, executing this method will ALWAYS clear any state which might have been saved to the session. This is what enforces the "single restore" type functionality.
      Parameters:
        `ec` - an ExternalContext
      Returns:
        the RequestStateMap for this ExternalContext

    - #### saveState

          public void saveState(javax.faces.context.ExternalContext ec)

      Saves the current state to the session. Running this is only manditory if you need to preserve a request across the natural request boundry in a portlet environment. Executing this function outside of a portlet environment will not alter operation of his class.
      Parameters:
        `ec` - the ExternalContext to save the stateMap to.

Copyright © 2001-2017 The Apache Software Foundation. All Rights Reserved.