diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java index d0d613d86bd..51b34f26251 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMethodAdapter.java @@ -59,7 +59,6 @@ import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.method.HandlerMethod; import org.springframework.web.method.HandlerMethodSelector; -import org.springframework.web.method.annotation.InitBinderMethodDataBinderFactory; import org.springframework.web.method.annotation.ModelFactory; import org.springframework.web.method.annotation.SessionAttributesHandler; import org.springframework.web.method.annotation.support.ErrorsMethodArgumentResolver; @@ -95,23 +94,23 @@ import org.springframework.web.util.WebUtils; /** * An {@link AbstractHandlerMethodAdapter} variant with support for {@link RequestMapping} handler methods. - * - *
Processing a {@link RequestMapping} method typically involves the invocation of {@link ModelAttribute} - * methods for contributing attributes to the model and {@link InitBinder} methods for initializing + * + *
Processing a {@link RequestMapping} method typically involves the invocation of {@link ModelAttribute} + * methods for contributing attributes to the model and {@link InitBinder} methods for initializing * {@link WebDataBinder} instances for data binding and type conversion purposes. - * - *
{@link InvocableHandlerMethod} is the key contributor that helps with the invocation of handler - * methods of all types resolving their arguments through registered {@link HandlerMethodArgumentResolver}s. + * + *
{@link InvocableHandlerMethod} is the key contributor that helps with the invocation of handler + * methods of all types resolving their arguments through registered {@link HandlerMethodArgumentResolver}s. * {@link ServletInvocableHandlerMethod} on the other hand adds handling of the return value for {@link RequestMapping} - * methods through registered {@link HandlerMethodReturnValueHandler}s resulting in a {@link ModelAndView}. - * - *
{@link ModelFactory} is another contributor that assists with the invocation of all {@link ModelAttribute} - * methods to populate a model while {@link InitBinderMethodDataBinderFactory} assists with the invocation of + * methods through registered {@link HandlerMethodReturnValueHandler}s resulting in a {@link ModelAndView}. + * + *
{@link ModelFactory} is another contributor that assists with the invocation of all {@link ModelAttribute} + * methods to populate a model while {@link ServletRequestDataBinderFactory} assists with the invocation of * {@link InitBinder} methods for initializing data binder instances when needed. - * - *
This class is the central point that assembles all of mentioned contributors and invokes the actual + * + *
This class is the central point that assembles all of mentioned contributors and invokes the actual * {@link RequestMapping} handler method through a {@link ServletInvocableHandlerMethod}. - * + * * @author Rossen Stoyanchev * @since 3.1 * @see InvocableHandlerMethod @@ -172,18 +171,18 @@ public class RequestMappingHandlerMethodAdapter extends AbstractHandlerMethodAda /** * Set one or more custom argument resolvers to use with {@link RequestMapping}, {@link ModelAttribute}, and - * {@link InitBinder} methods. Custom argument resolvers are given a chance to resolve argument values + * {@link InitBinder} methods. Custom argument resolvers are given a chance to resolve argument values * ahead of the standard argument resolvers registered by default. - *
An existing {@link WebArgumentResolver} can either adapted with {@link ServletWebArgumentResolverAdapter} - * or preferably converted to a {@link HandlerMethodArgumentResolver} instead. + *
An existing {@link WebArgumentResolver} can either adapted with {@link ServletWebArgumentResolverAdapter}
+ * or preferably converted to a {@link HandlerMethodArgumentResolver} instead.
*/
public void setCustomArgumentResolvers(List Custom {@link ModelAndViewResolver}s are provided for backward compatibility and are invoked at the very,
- * from the {@link DefaultMethodReturnValueHandler}, after all standard {@link HandlerMethodReturnValueHandler}s
- * have been given a chance. This is because {@link ModelAndViewResolver}s do not have a method to indicate
- * if they support a given return type or not. For this reason it is recommended to use
+ * Custom {@link ModelAndViewResolver}s are provided for backward compatibility and are invoked at the very,
+ * from the {@link DefaultMethodReturnValueHandler}, after all standard {@link HandlerMethodReturnValueHandler}s
+ * have been given a chance. This is because {@link ModelAndViewResolver}s do not have a method to indicate
+ * if they support a given return type or not. For this reason it is recommended to use
* {@link HandlerMethodReturnValueHandler} and {@link #setCustomReturnValueHandlers(List)} instead.
*/
public void setModelAndViewResolvers(List This method creates a {@link ServletRequestDataBinder} instance that also adds URI template variables to
@@ -90,4 +100,4 @@ public class ServletInitBinderMethodDataBinderFactory extends InitBinderMethodDa
}
}
-}
\ No newline at end of file
+}
diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInitBinderMethodDataBinderFactoryTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactoryTests.java
similarity index 89%
rename from org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInitBinderMethodDataBinderFactoryTests.java
rename to org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactoryTests.java
index 37bd0b50227..468b0fd1643 100644
--- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletInitBinderMethodDataBinderFactoryTests.java
+++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactoryTests.java
@@ -34,13 +34,13 @@ import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.servlet.HandlerMapping;
/**
- * Test fixture with {@link ServletInitBinderMethodDataBinderFactory}.
- *
+ * Test fixture with {@link ServletRequestDataBinderFactory}.
+ *
* @author Rossen Stoyanchev
*/
-public class ServletInitBinderMethodDataBinderFactoryTests {
+public class ServletRequestDataBinderFactoryTests {
- private ServletInitBinderMethodDataBinderFactory binderFactory;
+ private ServletRequestDataBinderFactory binderFactory;
private MockHttpServletRequest request;
@@ -48,7 +48,7 @@ public class ServletInitBinderMethodDataBinderFactoryTests {
@Before
public void setup() {
- binderFactory = new ServletInitBinderMethodDataBinderFactory(null, null);
+ binderFactory = new ServletRequestDataBinderFactory(null, null);
request = new MockHttpServletRequest();
webRequest = new ServletWebRequest(request);
RequestContextHolder.setRequestAttributes(webRequest);
diff --git a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactory.java b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
similarity index 81%
rename from org.springframework.web/src/main/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactory.java
rename to org.springframework.web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
index 548ca7d0e4c..327e5417008 100644
--- a/org.springframework.web/src/main/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactory.java
+++ b/org.springframework.web/src/main/java/org/springframework/web/method/annotation/InitBinderDataBinderFactory.java
@@ -30,32 +30,32 @@ import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.InvocableHandlerMethod;
/**
- * A specialization of {@link DefaultDataBinderFactory} that further initializes {@link WebDataBinder} instances
- * by invoking {@link InitBinder} methods.
- *
+ * A specialization of {@link DefaultDataBinderFactory} that further initializes {@link WebDataBinder} instances
+ * by invoking {@link InitBinder} methods.
+ *
* @author Rossen Stoyanchev
* @since 3.1
*/
-public class InitBinderMethodDataBinderFactory extends DefaultDataBinderFactory {
+public class InitBinderDataBinderFactory extends DefaultDataBinderFactory {
private final List A model attribute argument value is obtained from the model or is created using its default constructor.
+ *
+ * A model attribute argument value is obtained from the model or is created using its default constructor.
* Data binding and optionally validation is then applied through a {@link WebDataBinder} instance. Validation is
- * invoked optionally when the argument is annotated with an {@code @Valid}.
- *
- * Also handles return values from methods annotated with an @{@link ModelAttribute}. The return value is
- * added to the {@link ModelAndViewContainer}.
- *
+ * invoked optionally when the argument is annotated with an {@code @Valid}.
+ *
+ * Also handles return values from methods annotated with an @{@link ModelAttribute}. The return value is
+ * added to the {@link ModelAndViewContainer}.
+ *
* @author Rossen Stoyanchev
* @since 3.1
*/
@@ -54,7 +54,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
/**
* @param useDefaultResolution in default resolution mode a method argument that isn't a simple type, as
- * defined in {@link BeanUtils#isSimpleProperty(Class)}, is treated as a model attribute even if it doesn't
+ * defined in {@link BeanUtils#isSimpleProperty(Class)}, is treated as a model attribute even if it doesn't
* have an @{@link ModelAttribute} annotation with its name derived from the model attribute type.
*/
public ModelAttributeMethodProcessor(boolean useDefaultResolution) {
@@ -62,8 +62,8 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
}
/**
- * @return true if the parameter is annotated with {@link ModelAttribute} or if it is a
- * simple type without any annotations.
+ * @return true if the parameter is annotated with {@link ModelAttribute} or if it is a
+ * simple type without any annotations.
*/
public boolean supportsParameter(MethodParameter parameter) {
if (parameter.hasParameterAnnotation(ModelAttribute.class)) {
@@ -79,14 +79,14 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
/**
* Resolves the argument to a model attribute looking up the attribute in the model or instantiating it using its
- * default constructor. Data binding and optionally validation is then applied through a {@link WebDataBinder}
+ * default constructor. Data binding and optionally validation is then applied through a {@link WebDataBinder}
* instance. Validation is invoked optionally when the method parameter is annotated with an {@code @Valid}.
- *
- * @throws Exception if a {@link WebDataBinder} could not be created or if data binding and validation result in
+ *
+ * @throws Exception if a {@link WebDataBinder} could not be created or if data binding and validation result in
* an error and the next method parameter is not of type {@link Errors} or {@link BindingResult}.
*/
- public final Object resolveArgument(MethodParameter parameter,
- ModelAndViewContainer mavContainer,
+ public final Object resolveArgument(MethodParameter parameter,
+ ModelAndViewContainer mavContainer,
NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
WebDataBinder binder = createDataBinder(parameter, mavContainer, webRequest, binderFactory);
@@ -111,9 +111,9 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
/**
* Creates a {@link WebDataBinder} for a target object.
*/
- private WebDataBinder createDataBinder(MethodParameter parameter,
- ModelAndViewContainer mavContainer,
- NativeWebRequest webRequest,
+ private WebDataBinder createDataBinder(MethodParameter parameter,
+ ModelAndViewContainer mavContainer,
+ NativeWebRequest webRequest,
WebDataBinderFactory binderFactory) throws Exception {
String attrName = ModelFactory.getNameForParameter(parameter);
@@ -128,13 +128,19 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
return binderFactory.createBinder(webRequest, target, attrName);
}
+ /**
+ * Bind the request to the target object contained in the provided binder instance.
+ *
+ * @param binder the binder with the target object to apply request values to
+ * @param request the current request
+ */
protected void doBind(WebDataBinder binder, NativeWebRequest request) {
((WebRequestDataBinder) binder).bind(request);
}
/**
* Whether to validate the target object of the given {@link WebDataBinder} instance.
- * @param binder the data binder containing the validation candidate
+ * @param binder the data binder containing the validation candidate
* @param parameter the method argument for which data binding is performed
* @return true if {@link DataBinder#validate()} should be invoked, false otherwise.
*/
@@ -150,7 +156,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
/**
* Whether to raise a {@link BindException} in case of data binding or validation errors.
- * @param binder the binder on which validation is to be invoked
+ * @param binder the binder on which validation is to be invoked
* @param parameter the method argument for which data binding is performed
* @return true if the binding or validation errors should result in a {@link BindException}, false otherwise.
*/
@@ -166,8 +172,8 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
return returnType.getMethodAnnotation(ModelAttribute.class) != null;
}
- public void handleReturnValue(Object returnValue,
- MethodParameter returnType,
+ public void handleReturnValue(Object returnValue,
+ MethodParameter returnType,
ModelAndViewContainer mavContainer,
NativeWebRequest webRequest) throws Exception {
if (returnValue != null) {
diff --git a/org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactoryTests.java b/org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java
similarity index 96%
rename from org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactoryTests.java
rename to org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java
index 0876d9e0c20..fa18de22c9a 100644
--- a/org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderMethodDataBinderFactoryTests.java
+++ b/org.springframework.web/src/test/java/org/springframework/web/method/annotation/InitBinderDataBinderFactoryTests.java
@@ -43,11 +43,11 @@ import org.springframework.web.method.support.InvocableHandlerMethod;
import org.springframework.web.method.support.HandlerMethodArgumentResolverComposite;
/**
- * Test fixture with {@link InitBinderMethodDataBinderFactory}.
- *
+ * Test fixture with {@link InitBinderDataBinderFactory}.
+ *
* @author Rossen Stoyanchev
*/
-public class InitBinderMethodDataBinderFactoryTests {
+public class InitBinderDataBinderFactoryTests {
private ConfigurableWebBindingInitializer bindingInitializer;
@@ -128,7 +128,7 @@ public class InitBinderMethodDataBinderFactoryTests {
handlerMethod.setDataBinderFactory(new DefaultDataBinderFactory(null));
handlerMethod.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
- return new InitBinderMethodDataBinderFactory(Arrays.asList(handlerMethod), bindingInitializer);
+ return new InitBinderDataBinderFactory(Arrays.asList(handlerMethod), bindingInitializer);
}
private static class InitBinderHandler {