public class SessionAttributesHandler
extends java.lang.Object
@SessionAttributes
. Actual storage is
delegated to a SessionAttributeStore
instance.
When a controller annotated with @SessionAttributes
adds
attributes to its model, those attributes are checked against names and
types specified via @SessionAttributes
. Matching model attributes
are saved in the HTTP session and remain there until the controller calls
SessionStatus.setComplete()
.
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.lang.String> |
attributeNames |
private java.util.Set<java.lang.Class<?>> |
attributeTypes |
private java.util.Set<java.lang.String> |
knownAttributeNames |
private SessionAttributeStore |
sessionAttributeStore |
Constructor and Description |
---|
SessionAttributesHandler(java.lang.Class<?> handlerType,
SessionAttributeStore sessionAttributeStore)
Create a new instance for a controller type.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanupAttributes(WebRequest request)
Remove "known" attributes from the session, i.e.
|
boolean |
hasSessionAttributes()
Whether the controller represented by this instance has declared any
session attributes through an
SessionAttributes annotation. |
boolean |
isHandlerSessionAttribute(java.lang.String attributeName,
java.lang.Class<?> attributeType)
Whether the attribute name or type match the names and types specified
via
@SessionAttributes in underlying controller. |
(package private) java.lang.Object |
retrieveAttribute(WebRequest request,
java.lang.String attributeName)
A pass-through call to the underlying
SessionAttributeStore . |
java.util.Map<java.lang.String,java.lang.Object> |
retrieveAttributes(WebRequest request)
Retrieve "known" attributes from the session, i.e.
|
void |
storeAttributes(WebRequest request,
java.util.Map<java.lang.String,?> attributes)
Store a subset of the given attributes in the session.
|
private final java.util.Set<java.lang.String> attributeNames
private final java.util.Set<java.lang.Class<?>> attributeTypes
private final java.util.Set<java.lang.String> knownAttributeNames
private final SessionAttributeStore sessionAttributeStore
public SessionAttributesHandler(java.lang.Class<?> handlerType, SessionAttributeStore sessionAttributeStore)
@SessionAttributes
annotation, if
present, on the given type.handlerType
- the controller typesessionAttributeStore
- used for session accesspublic boolean hasSessionAttributes()
SessionAttributes
annotation.public boolean isHandlerSessionAttribute(java.lang.String attributeName, java.lang.Class<?> attributeType)
@SessionAttributes
in underlying controller.
Attributes successfully resolved through this method are "remembered"
and subsequently used in retrieveAttributes(WebRequest)
and
cleanupAttributes(WebRequest)
.
attributeName
- the attribute name to check, never null
attributeType
- the type for the attribute, possibly null
public void storeAttributes(WebRequest request, java.util.Map<java.lang.String,?> attributes)
@SessionAttributes
are ignored.request
- the current requestattributes
- candidate attributes for session storagepublic java.util.Map<java.lang.String,java.lang.Object> retrieveAttributes(WebRequest request)
@SessionAttributes
or attributes previously stored
in the model that matched by type.request
- the current requestpublic void cleanupAttributes(WebRequest request)
@SessionAttributes
or attributes previously stored
in the model that matched by type.request
- the current requestjava.lang.Object retrieveAttribute(WebRequest request, java.lang.String attributeName)
SessionAttributeStore
.request
- the current requestattributeName
- the name of the attribute of interestnull