SPR-8217 update MVC namespace to use HandlerMethod infrastructure
This commit is contained in:
@@ -64,7 +64,7 @@ public class ModelAttributeMethodProcessor
|
||||
if (parameter.hasParameterAnnotation(ModelAttribute.class)) {
|
||||
return true;
|
||||
}
|
||||
else if (this.resolveArgumentsWithoutAnnotations && !parameter.hasParameterAnnotations()) {
|
||||
else if (this.resolveArgumentsWithoutAnnotations) {
|
||||
return !BeanUtils.isSimpleProperty(parameter.getParameterType());
|
||||
}
|
||||
else {
|
||||
@@ -164,8 +164,10 @@ public class ModelAttributeMethodProcessor
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
|
||||
mavContainer.addModelAttribute(name, returnValue);
|
||||
if (returnValue != null) {
|
||||
String name = ModelFactory.getNameForReturnValue(returnValue, returnType);
|
||||
mavContainer.addModelAttribute(name, returnValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,12 +74,19 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
}
|
||||
if (returnValue instanceof Model) {
|
||||
mavContainer.addModelAttributes((Model) returnValue);
|
||||
}
|
||||
else {
|
||||
else if (returnValue instanceof Map){
|
||||
mavContainer.addModelAttributes((Map) returnValue);
|
||||
}
|
||||
else {
|
||||
// should not happen
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.web.method.annotation.support;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -31,9 +33,13 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
* Adapts a {@link WebArgumentResolver} into the {@link HandlerMethodArgumentResolver} contract.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
public class WebArgumentResolverAdapter implements HandlerMethodArgumentResolver {
|
||||
|
||||
private final Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final WebArgumentResolver adaptee;
|
||||
|
||||
public WebArgumentResolverAdapter(WebArgumentResolver adaptee) {
|
||||
@@ -43,14 +49,8 @@ public class WebArgumentResolverAdapter implements HandlerMethodArgumentResolver
|
||||
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
try {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
Object result ;
|
||||
if (requestAttributes instanceof NativeWebRequest) {
|
||||
result = adaptee.resolveArgument(parameter, (NativeWebRequest) requestAttributes);
|
||||
}
|
||||
else {
|
||||
result = adaptee.resolveArgument(parameter, null);
|
||||
}
|
||||
NativeWebRequest webRequest = getWebRequest();
|
||||
Object result = adaptee.resolveArgument(parameter, webRequest);
|
||||
if (result == WebArgumentResolver.UNRESOLVED) {
|
||||
return false;
|
||||
}
|
||||
@@ -60,9 +60,15 @@ public class WebArgumentResolverAdapter implements HandlerMethodArgumentResolver
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// ignore
|
||||
logger.trace("Error in checking support for parameter [" + parameter + "], message: " + ex.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected NativeWebRequest getWebRequest() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
return (requestAttributes instanceof NativeWebRequest) ? (NativeWebRequest) requestAttributes : null;
|
||||
}
|
||||
|
||||
public boolean usesResponseArgument(MethodParameter parameter) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user