SPR-6909 Include URI template vars in data binding
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.web.method.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -41,13 +42,13 @@ public class InitBinderMethodDataBinderFactory extends DefaultDataBinderFactory
|
||||
|
||||
/**
|
||||
* Create an {@code InitBinderMethodDataBinderFactory} instance with the given {@link InitBinder} methods.
|
||||
* @param initBinderMethods {@link InitBinder} methods to use to invoke to initialize new data binder instances
|
||||
* @param binderMethods {@link InitBinder} methods to use to invoke to initialize new data binder instances
|
||||
* @param bindingInitializer a {@link WebBindingInitializer} to initialize new data binder instances with
|
||||
*/
|
||||
public InitBinderMethodDataBinderFactory(List<InvocableHandlerMethod> initBinderMethods,
|
||||
public InitBinderMethodDataBinderFactory(List<InvocableHandlerMethod> binderMethods,
|
||||
WebBindingInitializer bindingInitializer) {
|
||||
super(bindingInitializer);
|
||||
this.initBinderMethods = initBinderMethods;
|
||||
this.initBinderMethods = (binderMethods != null) ? binderMethods : new ArrayList<InvocableHandlerMethod>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -94,11 +94,11 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
if (binder.getTarget() != null) {
|
||||
doBind(binder, webRequest);
|
||||
|
||||
if (shouldValidate(parameter)) {
|
||||
if (shouldValidate(binder, parameter)) {
|
||||
binder.validate();
|
||||
}
|
||||
|
||||
if (failOnError(parameter) && binder.getBindingResult().hasErrors()) {
|
||||
if (failOnError(binder, parameter) && binder.getBindingResult().hasErrors()) {
|
||||
throw new BindException(binder.getBindingResult());
|
||||
}
|
||||
}
|
||||
@@ -133,9 +133,12 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to validate the target object of the given {@link WebDataBinder} instance.
|
||||
* @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.
|
||||
*/
|
||||
protected boolean shouldValidate(MethodParameter parameter) {
|
||||
protected boolean shouldValidate(WebDataBinder binder, MethodParameter parameter) {
|
||||
Annotation[] annotations = parameter.getParameterAnnotations();
|
||||
for (Annotation annot : annotations) {
|
||||
if ("Valid".equals(annot.annotationType().getSimpleName())) {
|
||||
@@ -146,9 +149,12 @@ 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 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.
|
||||
*/
|
||||
protected boolean failOnError(MethodParameter parameter) {
|
||||
protected boolean failOnError(WebDataBinder binder, MethodParameter parameter) {
|
||||
int i = parameter.getParameterIndex();
|
||||
Class<?>[] paramTypes = parameter.getMethod().getParameterTypes();
|
||||
boolean hasBindingResult = (paramTypes.length > (i + 1) && Errors.class.isAssignableFrom(paramTypes[i + 1]));
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.support.BindingAwareModelMap;
|
||||
|
||||
/**
|
||||
* Provides access to the model and a place to record model and view related decisions to all
|
||||
* {@link HandlerMethodArgumentResolver}s and {@link HandlerMethodReturnValueHandler}s .
|
||||
* Provides access to the model and a place to record model and view related decisions made by
|
||||
* {@link HandlerMethodArgumentResolver}s or a {@link HandlerMethodReturnValueHandler}.
|
||||
*
|
||||
* <p>In addition to storing model attributes and a view, the {@link ModelAndViewContainer} also provides
|
||||
* a {@link #setResolveView(boolean)} flag, which can be used to request or bypass a view resolution phase.
|
||||
|
||||
Reference in New Issue
Block a user