|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.web.method.annotation.support.ModelAttributeMethodProcessor
public class ModelAttributeMethodProcessor
Resolves method arguments annotated with @ModelAttribute. Or if created in default resolution mode,
resolves any non-simple type argument even without an @ModelAttribute. See the constructor for details.
A model attribute argument is obtained from the model or otherwise is created with a default constructor.
Data binding and validation are applied through a WebDataBinder instance. Validation is applied
only when the argument is also annotated with @Valid.
Also handles return values from methods annotated with an @ModelAttribute. The return value is
added to the ModelAndViewContainer.
| Constructor Summary | |
|---|---|
ModelAttributeMethodProcessor(boolean useDefaultResolution)
|
|
| Method Summary | |
|---|---|
protected void |
doBind(WebDataBinder binder,
NativeWebRequest request)
Bind the request to the target object contained in the provided binder instance. |
protected boolean |
failOnError(WebDataBinder binder,
MethodParameter parameter)
Whether to raise a BindException in case of data binding or validation errors. |
void |
handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest)
Handle the given return value by adding attributes to the model, setting the view (or view name), or by writing to the response. |
Object |
resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory)
Resolves the argument to a model attribute looking up the attribute in the model or instantiating it using its default constructor. |
protected boolean |
shouldValidate(WebDataBinder binder,
MethodParameter parameter)
Whether to validate the target object of the given WebDataBinder instance. |
boolean |
supportsParameter(MethodParameter parameter)
Whether the given method parameter is supported by this resolver. |
boolean |
supportsReturnType(MethodParameter returnType)
Whether the given method return type is supported by this handler. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ModelAttributeMethodProcessor(boolean useDefaultResolution)
useDefaultResolution - in default resolution mode a method argument that isn't a simple type, as
defined in BeanUtils.isSimpleProperty(Class), is treated as a model attribute even if it doesn't
have an @ModelAttribute annotation with its name derived from the model attribute type.| Method Detail |
|---|
public boolean supportsParameter(MethodParameter parameter)
HandlerMethodArgumentResolver
supportsParameter in interface HandlerMethodArgumentResolverparameter - the method parameter to check
ModelAttribute or if it is a
simple type without any annotations.
public final Object resolveArgument(MethodParameter parameter,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory)
throws Exception
WebDataBinder
instance. Validation is invoked optionally when the method parameter is annotated with an @Valid.
resolveArgument in interface HandlerMethodArgumentResolverparameter - the method parameter to resolve. This parameter must have previously been passed to
HandlerMethodArgumentResolver.supportsParameter(org.springframework.core.MethodParameter) and it must have returned truemavContainer - the ModelAndViewContainer for the current requestwebRequest - the current requestbinderFactory - a factory for creating WebDataBinder instances
null.
Exception - if a WebDataBinder could not be created or if data binding and validation result in
an error and the next method parameter is not of type Errors or BindingResult.
protected void doBind(WebDataBinder binder,
NativeWebRequest request)
binder - the binder with the target object to apply request values torequest - the current request
protected boolean shouldValidate(WebDataBinder binder,
MethodParameter parameter)
WebDataBinder instance.
binder - the data binder containing the validation candidateparameter - the method argument for which data binding is performed
DataBinder.validate() should be invoked, false otherwise.
protected boolean failOnError(WebDataBinder binder,
MethodParameter parameter)
BindException in case of data binding or validation errors.
binder - the binder on which validation is to be invokedparameter - the method argument for which data binding is performed
BindException, false otherwise.public boolean supportsReturnType(MethodParameter returnType)
HandlerMethodReturnValueHandler
supportsReturnType in interface HandlerMethodReturnValueHandlerreturnType - the method return type to check
true if this handler supports the supplied return type; false otherwise
public void handleReturnValue(Object returnValue,
MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest)
throws Exception
HandlerMethodReturnValueHandlerHandlerMethodReturnValueHandler implementations should also
consider whether to set ModelAndViewContainer.setResolveView(boolean), which is set to
true by default and therefore needs to be set to false explicitly if view
resolution is to be bypassed.
handleReturnValue in interface HandlerMethodReturnValueHandlerreturnValue - the value returned from the handler methodreturnType - the type of the return value. This type must have previously been passed to
HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter) and it must have returned truemavContainer - the ModelAndViewContainer for the current requestwebRequest - the current request
Exception - if the return value handling results in an error
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||