request handler methods with @ModelAttribute annotation always return a model attribute (for Portlet MVC as well)
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@900 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
c25fe064ce
commit
61e640c85c
|
|
@ -53,8 +53,6 @@ import javax.portlet.WindowState;
|
||||||
import javax.servlet.http.Cookie;
|
import javax.servlet.http.Cookie;
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.core.Conventions;
|
|
||||||
import org.springframework.core.GenericTypeResolver;
|
|
||||||
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.core.ParameterNameDiscoverer;
|
import org.springframework.core.ParameterNameDiscoverer;
|
||||||
|
|
@ -681,12 +679,16 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl
|
||||||
else if (returnValue instanceof Model) {
|
else if (returnValue instanceof Model) {
|
||||||
return new ModelAndView().addAllObjects(implicitModel).addAllObjects(((Model) returnValue).asMap());
|
return new ModelAndView().addAllObjects(implicitModel).addAllObjects(((Model) returnValue).asMap());
|
||||||
}
|
}
|
||||||
else if (returnValue instanceof Map) {
|
|
||||||
return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map) returnValue);
|
|
||||||
}
|
|
||||||
else if (returnValue instanceof View) {
|
else if (returnValue instanceof View) {
|
||||||
return new ModelAndView(returnValue).addAllObjects(implicitModel);
|
return new ModelAndView(returnValue).addAllObjects(implicitModel);
|
||||||
}
|
}
|
||||||
|
else if (handlerMethod.isAnnotationPresent(ModelAttribute.class)) {
|
||||||
|
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
|
||||||
|
return new ModelAndView().addAllObjects(implicitModel);
|
||||||
|
}
|
||||||
|
else if (returnValue instanceof Map) {
|
||||||
|
return new ModelAndView().addAllObjects(implicitModel).addAllObjects((Map) returnValue);
|
||||||
|
}
|
||||||
else if (returnValue instanceof String) {
|
else if (returnValue instanceof String) {
|
||||||
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
|
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
|
||||||
}
|
}
|
||||||
|
|
@ -696,14 +698,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl
|
||||||
}
|
}
|
||||||
else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
|
else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
|
||||||
// Assume a single model attribute...
|
// Assume a single model attribute...
|
||||||
ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
|
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
|
||||||
String attrName = (attr != null ? attr.value() : "");
|
return new ModelAndView().addAllObjects(implicitModel);
|
||||||
ModelAndView mav = new ModelAndView().addAllObjects(implicitModel);
|
|
||||||
if ("".equals(attrName)) {
|
|
||||||
Class resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
|
|
||||||
attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
|
|
||||||
}
|
|
||||||
return mav.addObject(attrName, returnValue);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
|
throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue