public final class ModelFactory extends Object
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.| Constructor and Description |
|---|
ModelFactory(List<InvocableHandlerMethod> attributeMethods,
WebDataBinderFactory binderFactory,
SessionAttributesHandler sessionAttributesHandler)
Create a new instance with the given
@ModelAttribute methods. |
| Modifier and Type | Method and Description |
|---|---|
static String |
getNameForParameter(MethodParameter parameter)
Derives the model attribute name for a method parameter based on:
The parameter
@ModelAttribute annotation value
The parameter type
|
static String |
getNameForReturnValue(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.
|
void |
updateModel(NativeWebRequest request,
ModelAndViewContainer mavContainer)
Synchronize model attributes with the session.
|
public ModelFactory(List<InvocableHandlerMethod> attributeMethods, WebDataBinderFactory binderFactory, SessionAttributesHandler sessionAttributesHandler)
@ModelAttribute methods.attributeMethods - for model initializationbinderFactory - for adding BindingResult attributessessionAttributesHandler - for access to session attributespublic void initModel(NativeWebRequest request, ModelAndViewContainer mavContainer, HandlerMethod handlerMethod) throws 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 initializedException - may arise from @ModelAttribute methodspublic static String getNameForReturnValue(Object returnValue, MethodParameter returnType)
ModelAttribute annotation value
Object
returnValue - the value returned from a method invocationreturnType - the return type of the methodnull nor emptypublic static String getNameForParameter(MethodParameter parameter)
@ModelAttribute annotation value
null or an empty stringpublic void updateModel(NativeWebRequest request, ModelAndViewContainer mavContainer) throws Exception
BindingResult
attributes where necessary.request - the current requestmavContainer - contains the model to updateException - if creating BindingResult attributes fails