|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.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.
Constructor Summary | |
---|---|
ModelFactory(List<InvocableHandlerMethod> attributeMethods,
WebDataBinderFactory binderFactory,
SessionAttributesHandler sessionAttributesHandler)
Create a new instance with the given @ModelAttribute methods. |
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ModelFactory(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 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
Exception
- 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 method
null
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 update
Exception
- if creating BindingResult attributes fails
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |