class SessionAttributesHandler
extends java.lang.Object
ModelInitializer
with managing model
attributes in the WebSession
based on model attribute names and types
declared va @SessionAttributes
.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 |
Constructor and Description |
---|
SessionAttributesHandler(java.lang.Class<?> handlerType)
Create a new session attributes handler.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanupAttributes(WebSession session)
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 on the underlying controller. |
java.util.Map<java.lang.String,java.lang.Object> |
retrieveAttributes(WebSession session)
Retrieve "known" attributes from the session, i.e.
|
void |
storeAttributes(WebSession session,
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
public SessionAttributesHandler(java.lang.Class<?> handlerType)
@SessionAttributes
annotation, if present,
on the given type.handlerType
- the controller typepublic boolean hasSessionAttributes()
SessionAttributes
annotation.public boolean isHandlerSessionAttribute(java.lang.String attributeName, java.lang.Class<?> attributeType)
@SessionAttributes
on the underlying controller.
Attributes successfully resolved through this method are "remembered"
and subsequently used in retrieveAttributes(WebSession)
and also cleanupAttributes(WebSession)
.
attributeName
- the attribute name to checkattributeType
- the type for the attributepublic java.util.Map<java.lang.String,java.lang.Object> retrieveAttributes(WebSession session)
@SessionAttributes
or attributes previously stored
in the model that matched by type.session
- the current sessionpublic void storeAttributes(WebSession session, java.util.Map<java.lang.String,?> attributes)
@SessionAttributes
are ignored.session
- the current sessionattributes
- candidate attributes for session storagepublic void cleanupAttributes(WebSession session)
@SessionAttributes
or attributes previously stored
in the model that matched by type.session
- the current session