org.springframework.web.servlet.support
Class DefaultFlashMapManager

java.lang.Object
  extended by org.springframework.web.servlet.support.DefaultFlashMapManager
All Implemented Interfaces:
FlashMapManager

public class DefaultFlashMapManager
extends Object
implements FlashMapManager

A default FlashMapManager implementation that stores FlashMap instances in the HTTP session.

Since:
3.1
Author:
Rossen Stoyanchev

Field Summary
 
Fields inherited from interface org.springframework.web.servlet.FlashMapManager
INPUT_FLASH_MAP_ATTRIBUTE, OUTPUT_FLASH_MAP_ATTRIBUTE
 
Constructor Summary
DefaultFlashMapManager()
           
 
Method Summary
protected  boolean isFlashMapForRequest(FlashMap flashMap, HttpServletRequest request)
          Whether the given FlashMap matches the current request.
protected  void onSaveFlashMap(FlashMap flashMap, HttpServletRequest request)
          Update a FlashMap before it is stored in the HTTP Session.
 void requestCompleted(HttpServletRequest request)
          Start the expiration period of the "output" FlashMap save it in the underlying storage.
 void requestStarted(HttpServletRequest request)
          Perform the following tasks unless the FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE request attribute exists: Find the "input" FlashMap, expose it under the request attribute FlashMapManager.INPUT_FLASH_MAP_ATTRIBUTE, and remove it from underlying storage.
protected  List<FlashMap> retrieveFlashMaps(HttpServletRequest request, boolean allowCreate)
          Retrieve all FlashMap instances from the current HTTP session.
 void setFlashMapTimeout(int flashTimeout)
          Set the amount of time in seconds after a FlashMap is saved (at request completion) and before it expires.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFlashMapManager

public DefaultFlashMapManager()
Method Detail

setFlashMapTimeout

public void setFlashMapTimeout(int flashTimeout)
Set the amount of time in seconds after a FlashMap is saved (at request completion) and before it expires.

The default value is 180 seconds.


requestStarted

public void requestStarted(HttpServletRequest request)
Perform the following tasks unless the FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE request attribute exists:
  1. Find the "input" FlashMap, expose it under the request attribute FlashMapManager.INPUT_FLASH_MAP_ATTRIBUTE, and remove it from underlying storage.
  2. Create the "output" FlashMap and expose it under the request attribute FlashMapManager.OUTPUT_FLASH_MAP_ATTRIBUTE.
  3. Clean expired FlashMap instances.

An HTTP session is never created by this method.

Specified by:
requestStarted in interface FlashMapManager
Parameters:
request - the current request

isFlashMapForRequest

protected boolean isFlashMapForRequest(FlashMap flashMap,
                                       HttpServletRequest request)
Whether the given FlashMap matches the current request. The default implementation uses the target request path and query params saved in the FlashMap.


retrieveFlashMaps

protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request,
                                           boolean allowCreate)
Retrieve all FlashMap instances from the current HTTP session. If allowCreate is "true" and no flash maps exist yet, a new list is created and stored as a session attribute.

Parameters:
request - the current request
allowCreate - whether to create the session if necessary
Returns:
a List to add FlashMap instances to or null assuming allowCreate is "false".

requestCompleted

public void requestCompleted(HttpServletRequest request)
Start the expiration period of the "output" FlashMap save it in the underlying storage.

The "output" FlashMap should not be saved if it is empty or if it was not created by the current FlashMapManager instance.

An HTTP session is never created if the "output" FlashMap is empty.

Specified by:
requestCompleted in interface FlashMapManager
Parameters:
request - the current request

onSaveFlashMap

protected void onSaveFlashMap(FlashMap flashMap,
                              HttpServletRequest request)
Update a FlashMap before it is stored in the HTTP Session.

The default implementation starts the expiration period and ensures the target request path is decoded and normalized if it is relative.

Parameters:
flashMap - the flash map to be saved
request - the current request