|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.web.method.annotation.ModelFactory
public final class ModelFactory
Provides methods to initialize the Model
before controller method
invocation and to update it afterwards. On initialization, the model is
populated with attributes from the session or by invoking
@ModelAttribute
methods. On update, model attributes are
synchronized with the session -- either adding or removing them.
Also BindingResult
attributes where missing.
Field Summary | |
---|---|
private java.util.List<InvocableHandlerMethod> |
attributeMethods
|
private WebDataBinderFactory |
binderFactory
|
private SessionAttributesHandler |
sessionAttributesHandler
|
Constructor Summary | |
---|---|
ModelFactory(java.util.List<InvocableHandlerMethod> attributeMethods,
WebDataBinderFactory binderFactory,
SessionAttributesHandler sessionAttributesHandler)
Create a new instance with the given @ModelAttribute methods. |
Method Summary | |
---|---|
private java.util.List<java.lang.String> |
findSessionAttributeArguments(HandlerMethod handlerMethod)
Return all @ModelAttribute arguments declared as session
attributes via @SessionAttributes . |
static java.lang.String |
getNameForParameter(MethodParameter parameter)
Derives the model attribute name for a method parameter based on: The parameter @ModelAttribute annotation value
The parameter type
|
static java.lang.String |
getNameForReturnValue(java.lang.Object returnValue,
MethodParameter returnType)
Derive the model attribute name for the given return value using one of the following: The method ModelAttribute annotation value
The declared return type if it is other than Object
The actual return value type
|
void |
initModel(NativeWebRequest request,
ModelAndViewContainer mavContainer,
HandlerMethod handlerMethod)
Populate the model in the following order: Retrieve "known" session attributes -- i.e. |
private void |
invokeModelAttributeMethods(NativeWebRequest request,
ModelAndViewContainer mavContainer)
Invoke model attribute methods to populate the model. |
private boolean |
isBindingCandidate(java.lang.String attributeName,
java.lang.Object value)
Whether the given attribute requires a BindingResult in the model. |
private void |
updateBindingResult(NativeWebRequest request,
ModelMap model)
Add BindingResult attributes to the model for attributes that require it. |
void |
updateModel(NativeWebRequest request,
ModelAndViewContainer mavContainer)
Synchronize model attributes with the session. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final java.util.List<InvocableHandlerMethod> attributeMethods
private final WebDataBinderFactory binderFactory
private final SessionAttributesHandler sessionAttributesHandler
Constructor Detail |
---|
public ModelFactory(java.util.List<InvocableHandlerMethod> attributeMethods, WebDataBinderFactory binderFactory, SessionAttributesHandler sessionAttributesHandler)
@ModelAttribute
methods.
attributeMethods
- for model initializationbinderFactory
- for adding BindingResult
attributessessionAttributesHandler
- for access to session attributesMethod Detail |
---|
public void initModel(NativeWebRequest request, ModelAndViewContainer mavContainer, HandlerMethod handlerMethod) throws java.lang.Exception
@SessionAttributes
and previously stored in
the in the model at least once
@ModelAttribute
methods
request
- the current requestmavContainer
- contains the model to be initializedhandlerMethod
- the method for which the model is initialized
java.lang.Exception
- may arise from @ModelAttribute
methodsprivate void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewContainer mavContainer) throws java.lang.Exception
java.lang.Exception
private java.util.List<java.lang.String> findSessionAttributeArguments(HandlerMethod handlerMethod)
@ModelAttribute
arguments declared as session
attributes via @SessionAttributes
.
public static java.lang.String getNameForReturnValue(java.lang.Object returnValue, MethodParameter returnType)
ModelAttribute
annotation value
Object
returnValue
- the value returned from a method invocationreturnType
- the return type of the method
null
nor emptypublic static java.lang.String getNameForParameter(MethodParameter parameter)
@ModelAttribute
annotation value
null
or an empty stringpublic void updateModel(NativeWebRequest request, ModelAndViewContainer mavContainer) throws java.lang.Exception
BindingResult
attributes where necessary.
request
- the current requestmavContainer
- contains the model to update
java.lang.Exception
- if creating BindingResult attributes failsprivate void updateBindingResult(NativeWebRequest request, ModelMap model) throws java.lang.Exception
BindingResult
attributes to the model for attributes that require it.
java.lang.Exception
private boolean isBindingCandidate(java.lang.String attributeName, java.lang.Object value)
BindingResult
in the model.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |