From 84ea67669a12807bbc00c6ec6f30b6e754fff00f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 20 Feb 2009 11:48:26 +0000 Subject: [PATCH] ModelAndView's "cleared" state gets preserved in case of plain model Map access --- .../org/springframework/web/portlet/ModelAndView.java | 9 +++++---- .../handler/WebRequestHandlerInterceptorAdapter.java | 4 ++-- .../org/springframework/web/servlet/ModelAndView.java | 11 ++++++----- .../handler/WebRequestHandlerInterceptorAdapter.java | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/ModelAndView.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/ModelAndView.java index 26986de6b08..8d46a58c89a 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/ModelAndView.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/ModelAndView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.web.portlet; import java.util.Map; import org.springframework.ui.ModelMap; +import org.springframework.util.CollectionUtils; /** * Holder for both Model and View in the web MVC framework. @@ -50,7 +51,7 @@ public class ModelAndView { /** * Indicates whether or not this instance has been cleared with a call to {@link #clear()}. */ - private boolean cleared; + private boolean cleared = false; /** @@ -266,11 +267,11 @@ public class ModelAndView { } /** - * Return whether this ModelAndView object is empty + * Return whether this ModelAndView object is empty, * i.e. whether it does not hold any view and does not contain a model. */ public boolean isEmpty() { - return (this.view == null && this.model == null); + return (this.view == null && CollectionUtils.isEmpty(this.model)); } /** diff --git a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/WebRequestHandlerInterceptorAdapter.java b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/WebRequestHandlerInterceptorAdapter.java index a29cd0578ec..23155e87070 100644 --- a/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/WebRequestHandlerInterceptorAdapter.java +++ b/org.springframework.web.portlet/src/main/java/org/springframework/web/portlet/handler/WebRequestHandlerInterceptorAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,7 +100,7 @@ public class WebRequestHandlerInterceptorAdapter implements HandlerInterceptor { RenderRequest request, RenderResponse response, Object handler, ModelAndView modelAndView) throws Exception { this.requestInterceptor.postHandle(new PortletWebRequest(request), - (modelAndView != null ? modelAndView.getModelMap() : null)); + (modelAndView != null && !modelAndView.wasCleared() ? modelAndView.getModelMap() : null)); } public void afterRenderCompletion( diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/ModelAndView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/ModelAndView.java index 5a6fd426d81..f4d4a6742ba 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/ModelAndView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/ModelAndView.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ package org.springframework.web.servlet; import java.util.Map; import org.springframework.ui.ModelMap; +import org.springframework.util.CollectionUtils; /** * Holder for both Model and View in the web MVC framework. @@ -51,7 +52,7 @@ public class ModelAndView { /** * Indicates whether or not this instance has been cleared with a call to {@link #clear()}. */ - private boolean cleared; + private boolean cleared = false; /** @@ -267,17 +268,17 @@ public class ModelAndView { } /** - * Return whether this ModelAndView object is empty + * Return whether this ModelAndView object is empty, * i.e. whether it does not hold any view and does not contain a model. */ public boolean isEmpty() { - return (this.view == null && this.model == null); + return (this.view == null && CollectionUtils.isEmpty(this.model)); } /** * Return whether this ModelAndView object is empty as a result of a call to {@link #clear} * i.e. whether it does not hold any view and does not contain a model. - * Returns false if any additional state was added to the instance + *

Returns false if any additional state was added to the instance * after the call to {@link #clear}. * @see #clear() */ diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java index b1f5ea31815..1fe0976d277 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,7 @@ public class WebRequestHandlerInterceptorAdapter implements HandlerInterceptor { throws Exception { this.requestInterceptor.postHandle(new DispatcherServletWebRequest(request), - (modelAndView != null ? modelAndView.getModelMap() : null)); + (modelAndView != null && !modelAndView.wasCleared() ? modelAndView.getModelMap() : null)); } public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)