SPR-8976 Make flash attrs available to view controllers.

Previously flash attributes were automatically merged into the
model of annotated controllers only. This change extends the same
benefit to ParameterizableView- and UrlFilenameViewController,
both of which merely select a view without user controller logic
and (the views) would otherwise  not have access to the flash
attributes.
This commit is contained in:
Rossen Stoyanchev
2012-01-13 13:18:53 -05:00
parent be4e698483
commit b0c735feae
4 changed files with 91 additions and 3 deletions

View File

@@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.util.Assert;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.util.UrlPathHelper;
/**
@@ -86,7 +87,8 @@ public abstract class AbstractUrlViewController extends AbstractController {
/**
* Retrieves the URL path to use for lookup and delegates to
* {@link #getViewNameForRequest}.
* {@link #getViewNameForRequest}. Also adds the content of
* {@link RequestContextUtils#getInputFlashMap} to the model.
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
@@ -95,7 +97,7 @@ public abstract class AbstractUrlViewController extends AbstractController {
if (logger.isDebugEnabled()) {
logger.debug("Returning view name '" + viewName + "' for lookup path [" + lookupPath + "]");
}
return new ModelAndView(viewName);
return new ModelAndView(viewName, RequestContextUtils.getInputFlashMap(request));
}
/**

View File

@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.RequestContextUtils;
/**
* <p>Trivial controller that always returns a named view. The view
@@ -87,12 +88,13 @@ public class ParameterizableViewController extends AbstractController {
/**
* Return a ModelAndView object with the specified view name.
* The content of {@link RequestContextUtils#getInputFlashMap} is also added to the model.
* @see #getViewName()
*/
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception {
return new ModelAndView(getViewName());
return new ModelAndView(getViewName(), RequestContextUtils.getInputFlashMap(request));
}
}