Top Description Fields Constructors Methods
org.springframework.web.servlet

public final Class FlashMap

extends HashMap<String, Object>
implements Comparable<FlashMap>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Annotations
@SuppressWarnings:serial
Imports
java.util.HashMap, org.springframework.lang.Nullable, org.springframework.util.LinkedMultiValueMap, .MultiValueMap, .ObjectUtils, .StringUtils

A FlashMap provides a way for one request to store attributes intended for use in another. This is most commonly needed when redirecting from one URL to another -- e.g. the Post/Redirect/Get pattern. A FlashMap is saved before the redirect (typically in the session) and is made available after the redirect and removed immediately.

A FlashMap can be set up with a request path and request parameters to help identify the target request. Without this information, a FlashMap is made available to the next request, which may or may not be the intended recipient. On a redirect, the target URL is known and a FlashMap can be updated with that information. This is done automatically when the org.springframework.web.servlet.view.RedirectView is used.

Note

annotated controllers will usually not use FlashMap directly. See org.springframework.web.servlet.mvc.support.RedirectAttributes for an overview of using flash attributes in annotated controllers.

Author
Rossen Stoyanchev
Since
3.1
See Also
FlashMapManager

Field Summary

Modifier and TypeField and Description
private long
private final MultiValueMap<String, String>
private String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public FlashMap
addTargetRequestParam(String
the expected parameter name (skipped if empty)
name
,
String
the expected value (skipped if empty)
value
)

Provide a request parameter identifying the request for this FlashMap.

public FlashMap
addTargetRequestParams(MultiValueMap<String, String>
a Map with the names and values of expected parameters
params
)

Provide request parameters identifying the request for this FlashMap.

public int
compareTo(FlashMap
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compare two FlashMaps and prefer the one that specifies a target URL path or has more target URL parameters.

public boolean
equals(Object
object to be compared for equality with this map
other
)

Overrides java.util.AbstractMap.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.

public long
getExpirationTime()

Return the expiration time for the FlashMap or -1 if the expiration period has not started.

public MultiValueMap<String, String>
getTargetRequestParams()

Return the parameters identifying the target request, or an empty map.

public String
getTargetRequestPath()

Return the target URL path (or null if none specified).

public int
hashCode()

Overrides java.util.AbstractMap.hashCode.

Implements java.util.Map.hashCode.

Returns the hash code value for this map.

public boolean
isExpired()

Return whether this instance has expired depending on the amount of elapsed time since the call to startExpirationPeriod.

public void
setExpirationTime(long expirationTime)

Set the expiration time for the FlashMap.

public void
setTargetRequestPath(String path)

Provide a URL path to help identify the target request for this FlashMap.

public void
startExpirationPeriod(int
the number of seconds before expiration
timeToLive
)

Start the expiration period for this instance.

public String
toString()

Overrides java.util.AbstractMap.toString.

Returns a string representation of this map.

Inherited from java.util.HashMap:
clearclonecomputecomputeIfAbsentcomputeIfPresentcontainsKeycontainsValueentrySetforEachgetgetOrDefaultisEmptykeySetmergenewHashMapputputAllputIfAbsentremoveremovereplacereplacereplaceAllsizevalues

Field Detail

expirationTimeback to summary
private long expirationTime
targetRequestParamsback to summary
private final MultiValueMap<String, String> targetRequestParams
targetRequestPathback to summary
private String targetRequestPath
Annotations
@Nullable

Constructor Detail

FlashMapback to summary
public FlashMap()

Method Detail

addTargetRequestParamback to summary
public FlashMap addTargetRequestParam(String name, String value)

Provide a request parameter identifying the request for this FlashMap.

Parameters
name:String

the expected parameter name (skipped if empty)

value:String

the expected value (skipped if empty)

addTargetRequestParamsback to summary
public FlashMap addTargetRequestParams(MultiValueMap<String, String> params)

Provide request parameters identifying the request for this FlashMap.

Parameters
params:MultiValueMap<String, String>

a Map with the names and values of expected parameters

compareToback to summary
public int compareTo(FlashMap other)

Implements java.lang.Comparable.compareTo.

Compare two FlashMaps and prefer the one that specifies a target URL path or has more target URL parameters. Before comparing FlashMap instances ensure that they match a given request.

Parameters
other:FlashMap

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.util.AbstractMap.equals.

Implements java.util.Map.equals.

Doc from java.util.Map.equals.

Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()). This ensures that the equals method works properly across different implementations of the Map interface.

Parameters
other:Object

object to be compared for equality with this map

Returns:boolean

true if the specified object is equal to this map

Annotations
@Override
getExpirationTimeback to summary
public long getExpirationTime()

Return the expiration time for the FlashMap or -1 if the expiration period has not started.

Since
4.2
getTargetRequestParamsback to summary
public MultiValueMap<String, String> getTargetRequestParams()

Return the parameters identifying the target request, or an empty map.

getTargetRequestPathback to summary
public String getTargetRequestPath()

Return the target URL path (or null if none specified).

Annotations
@Nullable
hashCodeback to summary
public int hashCode()

Overrides java.util.AbstractMap.hashCode.

Implements java.util.Map.hashCode.

Doc from java.util.Map.hashCode.

Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract of Object#hashCode.

Returns:int

the hash code value for this map

Annotations
@Override
isExpiredback to summary
public boolean isExpired()

Return whether this instance has expired depending on the amount of elapsed time since the call to startExpirationPeriod.

setExpirationTimeback to summary
public void setExpirationTime(long expirationTime)

Set the expiration time for the FlashMap. This is provided for serialization purposes but can also be used instead startExpirationPeriod(int).

Since
4.2
setTargetRequestPathback to summary
public void setTargetRequestPath(String path)

Provide a URL path to help identify the target request for this FlashMap.

The path may be absolute (e.g. "/application/resource") or relative to the current request (e.g. "../resource").

startExpirationPeriodback to summary
public void startExpirationPeriod(int timeToLive)

Start the expiration period for this instance.

Parameters
timeToLive:int

the number of seconds before expiration

toStringback to summary
public String toString()

Overrides java.util.AbstractMap.toString.

Doc from java.util.AbstractMap.toString.

Returns a string representation of this map. The string representation consists of a list of key-value mappings in the order returned by the map's entrySet view's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value. Keys and values are converted to strings as by String#valueOf(Object).

Returns:String

a string representation of this map

Annotations
@Override