Top Description Fields Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class ServletModelAttributeMethodProcessor

extends ModelAttributeMethodProcessor
Class Inheritance
Imports
java.util.Collections, .Map, jakarta.servlet.ServletRequest, org.springframework.core.MethodParameter, org.springframework.core.convert.ConversionService, .TypeDescriptor, org.springframework.core.convert.converter.Converter, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils, org.springframework.validation.DataBinder, org.springframework.web.bind.ServletRequestDataBinder, .WebDataBinder, org.springframework.web.bind.support.WebDataBinderFactory, org.springframework.web.context.request.NativeWebRequest, .RequestAttributes, org.springframework.web.method.annotation.ModelAttributeMethodProcessor, org.springframework.web.servlet.HandlerMapping

A Servlet-specific ModelAttributeMethodProcessor that applies data binding through a WebDataBinder of type ServletRequestDataBinder.

Also adds a fall-back strategy to instantiate the model attribute from a URI template variable or from a request parameter if the name matches the model attribute name and there is an appropriate type conversion strategy.

Authors
Rossen Stoyanchev, Juergen Hoeller
Since
3.1

Field Summary

Inherited from org.springframework.web.method.annotation.ModelAttributeMethodProcessor:
logger

Constructor Summary

AccessConstructor and Description
public
ServletModelAttributeMethodProcessor(boolean
if "true", non-simple method arguments and return values are considered model attributes with or without a @ModelAttribute annotation
annotationNotRequired
)

Class constructor.

Method Summary

Modifier and TypeMethod and Description
protected void
bindRequestParameters(WebDataBinder
the data binder instance to use for the binding
binder
,
NativeWebRequest
the current request
request
)

Overrides org.springframework.web.method.annotation.ModelAttributeMethodProcessor.bindRequestParameters.

Downcast to ServletRequestDataBinder to invoke bind(ServletRequest).

protected void
constructAttribute(WebDataBinder
the data binder instance to use for the binding
binder
,
NativeWebRequest
the current request
request
)

Overrides org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute.

Downcast to ServletRequestDataBinder to invoke constructTarget(ServletRequest).

protected final Object
createAttribute(String
the name of the attribute (never null)
attributeName
,
MethodParameter
the method parameter declaration
parameter
,
WebDataBinderFactory
for creating WebDataBinder instance
binderFactory
,
NativeWebRequest
the current request
request
)

Overrides org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

Instantiate the model attribute from a URI template variable or from a request parameter if the name matches to the model attribute name and if there is an appropriate type conversion strategy.

protected Object

Returns:

the created model attribute, or null if no suitable conversion found
createAttributeFromRequestValue
(String
the source value to create the model attribute from
sourceValue
,
String
the name of the attribute (never null)
attributeName
,
MethodParameter
the method parameter
parameter
,
WebDataBinderFactory
for creating WebDataBinder instance
binderFactory
,
NativeWebRequest
the current request
request
)

Create a model attribute from a String request value (e.g. URI template variable, request parameter) using type conversion.

protected String

Returns:

the request value to try to convert, or null if none
getRequestValueForAttribute
(String
the model attribute name
attributeName
,
NativeWebRequest
the current request
request
)

Obtain a value from the request that may be used to instantiate the model attribute through type conversion from String to the target type.

protected final Map<String, String>
Inherited from org.springframework.web.method.annotation.ModelAttributeMethodProcessor:
handleReturnValueisBindExceptionRequiredisBindExceptionRequiredresolveArgumentsupportsParametersupportsReturnTypevalidateIfApplicable

Constructor Detail

ServletModelAttributeMethodProcessorback to summary
public ServletModelAttributeMethodProcessor(boolean annotationNotRequired)

Class constructor.

Parameters
annotationNotRequired:boolean

if "true", non-simple method arguments and return values are considered model attributes with or without a @ModelAttribute annotation

Method Detail

bindRequestParametersback to summary
protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest request)

Overrides org.springframework.web.method.annotation.ModelAttributeMethodProcessor.bindRequestParameters.

Downcast to ServletRequestDataBinder to invoke bind(ServletRequest).

Parameters
binder:WebDataBinder

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.bindRequestParameters.

the data binder instance to use for the binding

request:NativeWebRequest

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.bindRequestParameters.

the current request

Annotations
@Override
constructAttributeback to summary
protected void constructAttribute(WebDataBinder binder, NativeWebRequest request)

Overrides org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute.

Downcast to ServletRequestDataBinder to invoke constructTarget(ServletRequest).

Parameters
binder:WebDataBinder

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute.

the data binder instance to use for the binding

request:NativeWebRequest

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.constructAttribute.

the current request

Annotations
@Override
createAttributeback to summary
protected final Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception

Overrides org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

Instantiate the model attribute from a URI template variable or from a request parameter if the name matches to the model attribute name and if there is an appropriate type conversion strategy. If none of these are true delegate back to the base class.

Parameters
attributeName:String

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

the name of the attribute (never null)

parameter:MethodParameter

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

the method parameter declaration

binderFactory:WebDataBinderFactory

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

for creating WebDataBinder instance

request:NativeWebRequest

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

the current request

Returns:Object

Doc from org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute.

the created model attribute, or null

Annotations
@Override
See Also
createAttributeFromRequestValue
createAttributeFromRequestValueback to summary
protected Object createAttributeFromRequestValue(String sourceValue, String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception

Create a model attribute from a String request value (e.g. URI template variable, request parameter) using type conversion.

The default implementation converts only if there is a registered Converter that can perform the conversion.

Parameters
sourceValue:String

the source value to create the model attribute from

attributeName:String

the name of the attribute (never null)

parameter:MethodParameter

the method parameter

binderFactory:WebDataBinderFactory

for creating WebDataBinder instance

request:NativeWebRequest

the current request

Returns:Object

the created model attribute, or null if no suitable conversion found

Annotations
@Nullable
getRequestValueForAttributeback to summary
protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request)

Obtain a value from the request that may be used to instantiate the model attribute through type conversion from String to the target type.

The default implementation looks for the attribute name to match a URI variable first and then a request parameter.

Parameters
attributeName:String

the model attribute name

request:NativeWebRequest

the current request

Returns:String

the request value to try to convert, or null if none

Annotations
@Nullable
getUriTemplateVariablesback to summary
protected final Map<String, String> getUriTemplateVariables(NativeWebRequest request)