Browse Source

request handler methods with @ModelAttribute annotation always return a model attribute (for Portlet MVC as well)

conversation
Juergen Hoeller 16 years ago
parent
commit
b5ca53eedf
  1. 22
      org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java

22
org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java

@ -53,8 +53,6 @@ import javax.portlet.WindowState; @@ -53,8 +53,6 @@ import javax.portlet.WindowState;
import javax.servlet.http.Cookie;
import org.springframework.beans.BeanUtils;
import org.springframework.core.Conventions;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
@ -681,12 +679,16 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl @@ -681,12 +679,16 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl
else if (returnValue instanceof Model) {
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) {
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) {
return new ModelAndView((String) returnValue).addAllObjects(implicitModel);
}
@ -696,14 +698,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl @@ -696,14 +698,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator impl
}
else if (!BeanUtils.isSimpleProperty(returnValue.getClass())) {
// Assume a single model attribute...
ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
String attrName = (attr != null ? attr.value() : "");
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);
addReturnValueAsModelAttribute(handlerMethod, handlerType, returnValue, implicitModel);
return new ModelAndView().addAllObjects(implicitModel);
}
else {
throw new IllegalArgumentException("Invalid handler method return value: " + returnValue);

Loading…
Cancel
Save