Spring Framework

org.springframework.web.servlet.mvc.method.annotation
Class ModelAndViewResolverMethodReturnValueHandler

java.lang.Object
  extended by org.springframework.web.servlet.mvc.method.annotation.ModelAndViewResolverMethodReturnValueHandler
All Implemented Interfaces:
HandlerMethodReturnValueHandler

public class ModelAndViewResolverMethodReturnValueHandler
extends java.lang.Object
implements HandlerMethodReturnValueHandler

This return value handler is intended to be ordered after all others as it attempts to handle _any_ return value type (i.e. returns true for all return types).

The return value is handled either with a 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 String), UnsupportedOperationException is raised.

Note: This class is primarily needed to support ModelAndViewResolver, which unfortunately cannot be properly adapted to the HandlerMethodReturnValueHandler contract since the HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter) method cannot be implemented. Hence ModelAndViewResolvers 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 a ModelAndViewResolver as HandlerMethodReturnValueHandler, which also provides better access to the return type and method information.

Since:
3.1
Author:
Rossen Stoyanchev

Constructor Summary
ModelAndViewResolverMethodReturnValueHandler(java.util.List<ModelAndViewResolver> mavResolvers)
          Create a new instance.
 
Method Summary
 void handleReturnValue(java.lang.Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest request)
          Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer.setRequestHandled(boolean) flag to true to indicate the response has been handled directly.
 boolean supportsReturnType(MethodParameter returnType)
          Always returns true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelAndViewResolverMethodReturnValueHandler

public ModelAndViewResolverMethodReturnValueHandler(java.util.List<ModelAndViewResolver> mavResolvers)
Create a new instance.

Method Detail

supportsReturnType

public boolean supportsReturnType(MethodParameter returnType)
Always returns true. See class-level note.

Specified by:
supportsReturnType in interface HandlerMethodReturnValueHandler
Parameters:
returnType - the method return type to check
Returns:
true if this handler supports the supplied return type; false otherwise

handleReturnValue

public void handleReturnValue(java.lang.Object returnValue,
                              MethodParameter returnType,
                              ModelAndViewContainer mavContainer,
                              NativeWebRequest request)
                       throws java.lang.Exception
Description copied from interface: HandlerMethodReturnValueHandler
Handle the given return value by adding attributes to the model and setting a view or setting the ModelAndViewContainer.setRequestHandled(boolean) flag to true to indicate the response has been handled directly.

Specified by:
handleReturnValue in interface HandlerMethodReturnValueHandler
Parameters:
returnValue - the value returned from the handler method
returnType - the type of the return value. This type must have previously been passed to HandlerMethodReturnValueHandler.supportsReturnType(org.springframework.core.MethodParameter) and it must have returned true
mavContainer - the ModelAndViewContainer for the current request
request - the current request
Throws:
java.lang.Exception - if the return value handling results in an error

Spring Framework