Polish "Support flash attrs..." and related classes
- Eliminate trailing whitespace
- Update long method signatures to follow framework whitespace
conventions
Based on the following search,
$ git grep -A3 '^.public .* .*([^\{;]*$' */src/main
the strong convention throughout the framework when dealing with
methods having long signatures (i.e. many parameters) is to break
immediately after the opening paren, indent two tabs deeper and break
lines around 90 characters as necessary. Such signatures should also
be followed by a newline after the opening curly brace to break
things up visually.
The files edited in this commit had a particularly different style of
intenting arguments to align with each other vertically, but the
alignment only worked if one's tabstop is set at four spaces.
When viewed at a different tabstop value, the effect is is jarring,
both in that it is misaligned and significantly different from most
of the framework. The convention described above reads well at any
tabstop value.
This commit is contained in:
committed by
Rossen Stoyanchev
parent
92f8446eea
commit
d7d1b495f2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -39,13 +39,13 @@ import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
/**
|
||||
* Resolves {@link HttpEntity} method argument values and also handles
|
||||
* both {@link HttpEntity} and {@link ResponseEntity} return values.
|
||||
*
|
||||
* <p>An {@link HttpEntity} return type has a set purpose. Therefore this
|
||||
* handler should be configured ahead of handlers that support any return
|
||||
* both {@link HttpEntity} and {@link ResponseEntity} return values.
|
||||
*
|
||||
* <p>An {@link HttpEntity} return type has a set purpose. Therefore this
|
||||
* handler should be configured ahead of handlers that support any return
|
||||
* value type annotated with {@code @ModelAttribute} or {@code @ResponseBody}
|
||||
* to ensure they don't take over.
|
||||
*
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
@@ -66,10 +66,9 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
return HttpEntity.class.equals(parameterType) || ResponseEntity.class.equals(parameterType);
|
||||
}
|
||||
|
||||
public Object resolveArgument(MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory)
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws IOException, HttpMediaTypeNotSupportedException {
|
||||
|
||||
HttpInputMessage inputMessage = createInputMessage(webRequest);
|
||||
@@ -100,11 +99,11 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
+ "in method " + parameter.getMethod() + "is not parameterized");
|
||||
}
|
||||
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
||||
if (returnValue == null) {
|
||||
@@ -135,4 +134,4 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,15 @@ import org.springframework.web.servlet.SmartView;
|
||||
import org.springframework.web.servlet.View;
|
||||
|
||||
/**
|
||||
* Handles return values of type {@link ModelAndView} copying view and model
|
||||
* Handles return values of type {@link ModelAndView} copying view and model
|
||||
* information to the {@link ModelAndViewContainer}.
|
||||
*
|
||||
* <p>If the return value is {@code null}, the
|
||||
* {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to
|
||||
*
|
||||
* <p>If the return value is {@code null}, the
|
||||
* {@link ModelAndViewContainer#setRequestHandled(boolean)} flag is set to
|
||||
* {@code false} to indicate the request was handled directly.
|
||||
*
|
||||
* <p>A {@link ModelAndView} return type has a set purpose. Therefore this
|
||||
* handler should be configured ahead of handlers that support any return
|
||||
*
|
||||
* <p>A {@link ModelAndView} return type has a set purpose. Therefore this
|
||||
* handler should be configured ahead of handlers that support any return
|
||||
* value type annotated with {@code @ModelAttribute} or {@code @ResponseBody}
|
||||
* to ensure they don't take over.
|
||||
*
|
||||
@@ -41,20 +41,21 @@ import org.springframework.web.servlet.View;
|
||||
* @since 3.1
|
||||
*/
|
||||
public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
|
||||
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return ModelAndView.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
mavContainer.setRequestHandled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ModelAndView mav = (ModelAndView) returnValue;
|
||||
if (mav.isReference()) {
|
||||
String viewName = mav.getViewName();
|
||||
@@ -75,4 +76,4 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn
|
||||
mavContainer.addAllAttributes(mav.getModel());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -29,25 +29,25 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver;
|
||||
|
||||
/**
|
||||
* This return value handler is intended to be ordered after all others as it
|
||||
* This return value handler is intended to be ordered after all others as it
|
||||
* attempts to handle _any_ return value type (i.e. returns {@code true} for
|
||||
* all return types).
|
||||
*
|
||||
*
|
||||
* <p>The return value is handled either with a {@link ModelAndViewResolver}
|
||||
* or otherwise by regarding it as a model attribute if it is a non-simple
|
||||
* type. If neither of these succeeds (essentially simple type other than
|
||||
* or otherwise by regarding it as a model attribute if it is a non-simple
|
||||
* type. If neither of these succeeds (essentially simple type other than
|
||||
* String), {@link UnsupportedOperationException} is raised.
|
||||
*
|
||||
* <p><strong>Note:</strong> This class is primarily needed to support
|
||||
*
|
||||
* <p><strong>Note:</strong> This class is primarily needed to support
|
||||
* {@link ModelAndViewResolver}, which unfortunately cannot be properly
|
||||
* adapted to the {@link HandlerMethodReturnValueHandler} contract since the
|
||||
* adapted to the {@link HandlerMethodReturnValueHandler} contract since the
|
||||
* {@link HandlerMethodReturnValueHandler#supportsReturnType} method
|
||||
* cannot be implemented. Hence {@code ModelAndViewResolver}s are limited
|
||||
* to always being invoked at the end after all other return value
|
||||
* handlers have been given a chance. It is recommended to re-implement
|
||||
* to always being invoked at the end after all other return value
|
||||
* handlers have been given a chance. It is recommended to re-implement
|
||||
* a {@code ModelAndViewResolver} as {@code HandlerMethodReturnValueHandler},
|
||||
* which also provides better access to the return type and method information.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
@@ -71,10 +71,10 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
||||
return true;
|
||||
}
|
||||
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest request) throws Exception {
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest request)
|
||||
throws Exception {
|
||||
|
||||
if (this.mavResolvers != null) {
|
||||
for (ModelAndViewResolver mavResolver : this.mavResolvers) {
|
||||
@@ -93,7 +93,7 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
||||
}
|
||||
}
|
||||
|
||||
// No suitable ModelAndViewResolver..
|
||||
// No suitable ModelAndViewResolver..
|
||||
|
||||
if (this.modelAttributeProcessor.supportsReturnType(returnType)) {
|
||||
this.modelAttributeProcessor.handleReturnValue(returnValue, returnType, mavContainer, request);
|
||||
@@ -104,4 +104,4 @@ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMeth
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -30,8 +30,8 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
|
||||
|
||||
/**
|
||||
* Resolves method arguments of type {@link RedirectAttributes}.
|
||||
*
|
||||
* Resolves method arguments of type {@link RedirectAttributes}.
|
||||
*
|
||||
* <p>This resolver must be listed ahead of {@link org.springframework.web.method.annotation.ModelMethodProcessor} and
|
||||
* {@link org.springframework.web.method.annotation.MapMethodProcessor}, which support {@link Map} and {@link Model}
|
||||
* arguments both of which are "super" types of {@code RedirectAttributes}
|
||||
@@ -46,10 +46,11 @@ public class RedirectAttributesMethodArgumentResolver implements HandlerMethodAr
|
||||
return RedirectAttributes.class.isAssignableFrom(parameter.getParameterType());
|
||||
}
|
||||
|
||||
public Object resolveArgument(MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory) throws Exception {
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
|
||||
DataBinder dataBinder = binderFactory.createBinder(webRequest, null, null);
|
||||
ModelMap redirectAttributes = new RedirectAttributesModelMap(dataBinder);
|
||||
mavContainer.setRedirectModel(redirectAttributes);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -89,9 +89,9 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||
* @param mavContainer the {@link ModelAndViewContainer} for the current request
|
||||
* @param providedArgs argument values to try to use without the need for view resolution
|
||||
*/
|
||||
public final void invokeAndHandle(NativeWebRequest request,
|
||||
ModelAndViewContainer mavContainer,
|
||||
Object...providedArgs) throws Exception {
|
||||
public final void invokeAndHandle(
|
||||
NativeWebRequest request, ModelAndViewContainer mavContainer,
|
||||
Object... providedArgs) throws Exception {
|
||||
|
||||
Object returnValue = invokeForRequest(request, mavContainer, providedArgs);
|
||||
|
||||
@@ -124,7 +124,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||
sb.append("[value=" + returnValue + "]");
|
||||
return getDetailedErrorMessage(sb.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set the response status according to the {@link ResponseStatus} annotation.
|
||||
*/
|
||||
@@ -157,4 +157,4 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod {
|
||||
private boolean hasResponseStatus() {
|
||||
return responseStatus != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -37,7 +37,7 @@ import org.springframework.web.multipart.MultipartRequest;
|
||||
import org.springframework.web.servlet.support.RequestContextUtils;
|
||||
|
||||
/**
|
||||
* Resolves request-related method argument values of the following types:
|
||||
* Resolves request-related method argument values of the following types:
|
||||
* <ul>
|
||||
* <li>{@link WebRequest}
|
||||
* <li>{@link ServletRequest}
|
||||
@@ -57,20 +57,20 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
return WebRequest.class.isAssignableFrom(paramType) ||
|
||||
return WebRequest.class.isAssignableFrom(paramType) ||
|
||||
ServletRequest.class.isAssignableFrom(paramType) ||
|
||||
MultipartRequest.class.isAssignableFrom(paramType) ||
|
||||
HttpSession.class.isAssignableFrom(paramType) ||
|
||||
HttpSession.class.isAssignableFrom(paramType) ||
|
||||
Principal.class.isAssignableFrom(paramType) ||
|
||||
Locale.class.equals(paramType) ||
|
||||
Locale.class.equals(paramType) ||
|
||||
InputStream.class.isAssignableFrom(paramType) ||
|
||||
Reader.class.isAssignableFrom(paramType);
|
||||
}
|
||||
|
||||
public Object resolveArgument(MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory) throws IOException {
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws IOException {
|
||||
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
if (WebRequest.class.isAssignableFrom(paramType)) {
|
||||
@@ -108,4 +108,4 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -47,20 +47,20 @@ public class ServletResponseMethodArgumentResolver implements HandlerMethodArgum
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
Class<?> paramType = parameter.getParameterType();
|
||||
return ServletResponse.class.isAssignableFrom(paramType)
|
||||
|| OutputStream.class.isAssignableFrom(paramType)
|
||||
|| OutputStream.class.isAssignableFrom(paramType)
|
||||
|| Writer.class.isAssignableFrom(paramType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@link ModelAndViewContainer#setRequestHandled(boolean)} to
|
||||
* {@code false} to indicate that the method signature provides access
|
||||
* to the response. If subsequently the underlying method returns
|
||||
* Set {@link ModelAndViewContainer#setRequestHandled(boolean)} to
|
||||
* {@code false} to indicate that the method signature provides access
|
||||
* to the response. If subsequently the underlying method returns
|
||||
* {@code null}, the request is considered directly handled.
|
||||
*/
|
||||
public Object resolveArgument(MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory) throws IOException {
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws IOException {
|
||||
|
||||
mavContainer.setRequestHandled(true);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
/**
|
||||
* Resolvers argument values of type {@link UriComponentsBuilder}.
|
||||
*
|
||||
*
|
||||
* <p>The returned instance is initialized via
|
||||
* {@link ServletUriComponentsBuilder#fromServletMapping(HttpServletRequest)}.
|
||||
*
|
||||
@@ -41,11 +41,11 @@ public class UriComponentsBuilderMethodArgumentResolver implements HandlerMethod
|
||||
return UriComponentsBuilder.class.isAssignableFrom(parameter.getParameterType());
|
||||
}
|
||||
|
||||
public Object resolveArgument(MethodParameter parameter,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest,
|
||||
WebDataBinderFactory binderFactory) throws Exception {
|
||||
|
||||
public Object resolveArgument(
|
||||
MethodParameter parameter, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory)
|
||||
throws Exception {
|
||||
|
||||
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
|
||||
return ServletUriComponentsBuilder.fromServletMapping(request);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -27,14 +27,14 @@ import org.springframework.web.servlet.View;
|
||||
/**
|
||||
* Handles return values that are of type {@link View}.
|
||||
*
|
||||
* <p>A {@code null} return value is left as-is leaving it to the configured
|
||||
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
||||
* <p>A {@code null} return value is left as-is leaving it to the configured
|
||||
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
||||
*
|
||||
* <p>A {@link View} return type has a set purpose. Therefore this handler
|
||||
* should be configured ahead of handlers that support any return value type
|
||||
* <p>A {@link View} return type has a set purpose. Therefore this handler
|
||||
* should be configured ahead of handlers that support any return value type
|
||||
* annotated with {@code @ModelAttribute} or {@code @ResponseBody} to ensure
|
||||
* they don't take over.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 3.1
|
||||
*/
|
||||
@@ -44,10 +44,11 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
||||
return View.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
}
|
||||
@@ -62,7 +63,7 @@ public class ViewMethodReturnValueHandler implements HandlerMethodReturnValueHan
|
||||
}
|
||||
else {
|
||||
// should not happen
|
||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -26,12 +26,12 @@ import org.springframework.web.servlet.RequestToViewNameTranslator;
|
||||
* Handles return values of types {@code void} and {@code String} interpreting
|
||||
* them as view name reference.
|
||||
*
|
||||
* <p>A {@code null} return value, either due to a {@code void} return type or
|
||||
* as the actual return value is left as-is allowing the configured
|
||||
* <p>A {@code null} return value, either due to a {@code void} return type or
|
||||
* as the actual return value is left as-is allowing the configured
|
||||
* {@link RequestToViewNameTranslator} to select a view name by convention.
|
||||
*
|
||||
* <p>A String return value can be interpreted in more than one ways depending
|
||||
* on the presence of annotations like {@code @ModelAttribute} or
|
||||
* <p>A String return value can be interpreted in more than one ways depending
|
||||
* on the presence of annotations like {@code @ModelAttribute} or
|
||||
* {@code @ResponseBody}. Therefore this handler should be configured after
|
||||
* the handlers that support these annotations.
|
||||
*
|
||||
@@ -45,10 +45,11 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
||||
return (void.class.equals(paramType) || String.class.equals(paramType));
|
||||
}
|
||||
|
||||
public void handleReturnValue(Object returnValue,
|
||||
MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
public void handleReturnValue(
|
||||
Object returnValue, MethodParameter returnType,
|
||||
ModelAndViewContainer mavContainer, NativeWebRequest webRequest)
|
||||
throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
}
|
||||
@@ -61,7 +62,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
||||
}
|
||||
else {
|
||||
// should not happen
|
||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||
throw new UnsupportedOperationException("Unexpected return type: " +
|
||||
returnType.getParameterType().getName() + " in method: " + returnType.getMethod());
|
||||
}
|
||||
}
|
||||
@@ -69,7 +70,7 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu
|
||||
/**
|
||||
* Whether the given view name is a redirect view reference.
|
||||
* @param viewName the view name to check, never {@code null}
|
||||
* @return "true" if the given view name is recognized as a redirect view
|
||||
* @return "true" if the given view name is recognized as a redirect view
|
||||
* reference; "false" otherwise.
|
||||
*/
|
||||
protected boolean isRedirectViewName(String viewName) {
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
/**
|
||||
* Test fixture with {@link ModelAndViewMethodReturnValueHandler}.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
@@ -57,7 +57,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
this.webRequest = new ServletWebRequest(new MockHttpServletRequest());
|
||||
this.returnParamModelAndView = getReturnValueParam("modelAndView");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void supportsReturnType() throws Exception {
|
||||
assertTrue(handler.supportsReturnType(returnParamModelAndView));
|
||||
@@ -68,7 +68,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
public void handleViewReference() throws Exception {
|
||||
ModelAndView mav = new ModelAndView("viewName", "attrName", "attrValue");
|
||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||
|
||||
|
||||
assertEquals("viewName", mavContainer.getView());
|
||||
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
public void handleViewInstance() throws Exception {
|
||||
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
|
||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||
|
||||
|
||||
assertEquals(RedirectView.class, mavContainer.getView().getClass());
|
||||
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
@Test
|
||||
public void handleNull() throws Exception {
|
||||
handler.handleReturnValue(null, returnParamModelAndView, mavContainer, webRequest);
|
||||
|
||||
|
||||
assertTrue(mavContainer.isRequestHandled());
|
||||
}
|
||||
|
||||
@@ -93,10 +93,10 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
public void handleRedirectAttributesWithViewReference() throws Exception {
|
||||
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
||||
mavContainer.setRedirectModel(redirectAttributes);
|
||||
|
||||
|
||||
ModelAndView mav = new ModelAndView(new RedirectView(), "attrName", "attrValue");
|
||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||
|
||||
|
||||
assertEquals(RedirectView.class, mavContainer.getView().getClass());
|
||||
assertEquals("attrValue", mavContainer.getModel().get("attrName"));
|
||||
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes,
|
||||
@@ -107,24 +107,24 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
public void handleRedirectAttributesWithViewInstance() throws Exception {
|
||||
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
||||
mavContainer.setRedirectModel(redirectAttributes);
|
||||
|
||||
|
||||
ModelAndView mav = new ModelAndView("redirect:viewName", "attrName", "attrValue");
|
||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||
|
||||
|
||||
ModelMap model = mavContainer.getModel();
|
||||
assertEquals("redirect:viewName", mavContainer.getViewName());
|
||||
assertEquals("attrValue", model.get("attrName"));
|
||||
assertSame("RedirectAttributes should be used if controller redirects", redirectAttributes, model);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void handleRedirectAttributesWithoutRedirect() throws Exception {
|
||||
RedirectAttributesModelMap redirectAttributes = new RedirectAttributesModelMap();
|
||||
mavContainer.setRedirectModel(redirectAttributes);
|
||||
|
||||
|
||||
ModelAndView mav = new ModelAndView();
|
||||
handler.handleReturnValue(mav, returnParamModelAndView, mavContainer, webRequest);
|
||||
|
||||
|
||||
ModelMap model = mavContainer.getModel();
|
||||
assertEquals(null, mavContainer.getView());
|
||||
assertTrue(mavContainer.getModel().isEmpty());
|
||||
@@ -136,7 +136,7 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
Method method = getClass().getDeclaredMethod(methodName);
|
||||
return new MethodParameter(method, -1);
|
||||
}
|
||||
|
||||
|
||||
ModelAndView modelAndView() {
|
||||
return null;
|
||||
}
|
||||
@@ -144,5 +144,5 @@ public class ModelAndViewMethodReturnValueHandlerTests {
|
||||
String viewName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user