Search in sources :

Example 1 with ModelMethodProcessor

use of org.springframework.web.method.annotation.ModelMethodProcessor in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapter method getDefaultArgumentResolvers.

/**
	 * Return the list of argument resolvers to use including built-in resolvers
	 * and custom resolvers provided via {@link #setCustomArgumentResolvers}.
	 */
private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
    List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
    // Annotation-based argument resolution
    resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
    resolvers.add(new RequestParamMapMethodArgumentResolver());
    resolvers.add(new PathVariableMethodArgumentResolver());
    resolvers.add(new PathVariableMapMethodArgumentResolver());
    resolvers.add(new MatrixVariableMethodArgumentResolver());
    resolvers.add(new MatrixVariableMapMethodArgumentResolver());
    resolvers.add(new ServletModelAttributeMethodProcessor(false));
    resolvers.add(new RequestResponseBodyMethodProcessor(getMessageConverters(), this.requestResponseBodyAdvice));
    resolvers.add(new RequestPartMethodArgumentResolver(getMessageConverters(), this.requestResponseBodyAdvice));
    resolvers.add(new RequestHeaderMethodArgumentResolver(getBeanFactory()));
    resolvers.add(new RequestHeaderMapMethodArgumentResolver());
    resolvers.add(new ServletCookieValueMethodArgumentResolver(getBeanFactory()));
    resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory()));
    resolvers.add(new SessionAttributeMethodArgumentResolver());
    resolvers.add(new RequestAttributeMethodArgumentResolver());
    // Type-based argument resolution
    resolvers.add(new ServletRequestMethodArgumentResolver());
    resolvers.add(new ServletResponseMethodArgumentResolver());
    resolvers.add(new HttpEntityMethodProcessor(getMessageConverters(), this.requestResponseBodyAdvice));
    resolvers.add(new RedirectAttributesMethodArgumentResolver());
    resolvers.add(new ModelMethodProcessor());
    resolvers.add(new MapMethodProcessor());
    resolvers.add(new ErrorsMethodArgumentResolver());
    resolvers.add(new SessionStatusMethodArgumentResolver());
    resolvers.add(new UriComponentsBuilderMethodArgumentResolver());
    // Custom arguments
    if (getCustomArgumentResolvers() != null) {
        resolvers.addAll(getCustomArgumentResolvers());
    }
    // Catch-all
    resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true));
    resolvers.add(new ServletModelAttributeMethodProcessor(true));
    return resolvers;
}
Also used : RequestParamMethodArgumentResolver(org.springframework.web.method.annotation.RequestParamMethodArgumentResolver) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) ArrayList(java.util.ArrayList) SessionStatusMethodArgumentResolver(org.springframework.web.method.annotation.SessionStatusMethodArgumentResolver) ExpressionValueMethodArgumentResolver(org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver) ErrorsMethodArgumentResolver(org.springframework.web.method.annotation.ErrorsMethodArgumentResolver) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) RequestParamMapMethodArgumentResolver(org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver) RequestHeaderMethodArgumentResolver(org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver) MapMethodProcessor(org.springframework.web.method.annotation.MapMethodProcessor) RequestHeaderMapMethodArgumentResolver(org.springframework.web.method.annotation.RequestHeaderMapMethodArgumentResolver)

Example 2 with ModelMethodProcessor

use of org.springframework.web.method.annotation.ModelMethodProcessor in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolver method getDefaultReturnValueHandlers.

/**
	 * Return the list of return value handlers to use including built-in and
	 * custom handlers provided via {@link #setReturnValueHandlers}.
	 */
protected List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() {
    List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();
    // Single-purpose return value types
    handlers.add(new ModelAndViewMethodReturnValueHandler());
    handlers.add(new ModelMethodProcessor());
    handlers.add(new ViewMethodReturnValueHandler());
    handlers.add(new HttpEntityMethodProcessor(getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));
    // Annotation-based return value types
    handlers.add(new ModelAttributeMethodProcessor(false));
    handlers.add(new RequestResponseBodyMethodProcessor(getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));
    // Multi-purpose return value types
    handlers.add(new ViewNameMethodReturnValueHandler());
    handlers.add(new MapMethodProcessor());
    // Custom return value types
    if (getCustomReturnValueHandlers() != null) {
        handlers.addAll(getCustomReturnValueHandlers());
    }
    // Catch-all
    handlers.add(new ModelAttributeMethodProcessor(true));
    return handlers;
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) MapMethodProcessor(org.springframework.web.method.annotation.MapMethodProcessor) ArrayList(java.util.ArrayList) ModelAttributeMethodProcessor(org.springframework.web.method.annotation.ModelAttributeMethodProcessor)

Example 3 with ModelMethodProcessor

use of org.springframework.web.method.annotation.ModelMethodProcessor in project spring-framework by spring-projects.

the class ExceptionHandlerExceptionResolver method getDefaultArgumentResolvers.

/**
	 * Return the list of argument resolvers to use including built-in resolvers
	 * and custom resolvers provided via {@link #setCustomArgumentResolvers}.
	 */
protected List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
    List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
    // Annotation-based argument resolution
    resolvers.add(new SessionAttributeMethodArgumentResolver());
    resolvers.add(new RequestAttributeMethodArgumentResolver());
    // Type-based argument resolution
    resolvers.add(new ServletRequestMethodArgumentResolver());
    resolvers.add(new ServletResponseMethodArgumentResolver());
    resolvers.add(new RedirectAttributesMethodArgumentResolver());
    resolvers.add(new ModelMethodProcessor());
    // Custom arguments
    if (getCustomArgumentResolvers() != null) {
        resolvers.addAll(getCustomArgumentResolvers());
    }
    return resolvers;
}
Also used : ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) ArrayList(java.util.ArrayList) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver)

Example 4 with ModelMethodProcessor

use of org.springframework.web.method.annotation.ModelMethodProcessor in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapterTests method setAlwaysUseRedirectAttributes.

@Test
public void setAlwaysUseRedirectAttributes() throws Exception {
    HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver();
    HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor();
    HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler();
    this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver));
    this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler));
    this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true);
    this.handlerAdapter.afterPropertiesSet();
    this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
    HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class);
    ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod);
    assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty());
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) FlashMap(org.springframework.web.servlet.FlashMap) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) ModelAndView(org.springframework.web.servlet.ModelAndView) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 5 with ModelMethodProcessor

use of org.springframework.web.method.annotation.ModelMethodProcessor in project spring-framework by spring-projects.

the class RequestMappingHandlerAdapterTests method setReturnValueHandlers.

@Test
public void setReturnValueHandlers() {
    HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
    this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(handler));
    this.handlerAdapter.afterPropertiesSet();
    assertMethodProcessorCount(RESOLVER_COUNT, INIT_BINDER_RESOLVER_COUNT, 1);
}
Also used : HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) ModelMethodProcessor(org.springframework.web.method.annotation.ModelMethodProcessor) Test(org.junit.Test)

Aggregations

ModelMethodProcessor (org.springframework.web.method.annotation.ModelMethodProcessor)7 HandlerMethodReturnValueHandler (org.springframework.web.method.support.HandlerMethodReturnValueHandler)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 MapMethodProcessor (org.springframework.web.method.annotation.MapMethodProcessor)3 HandlerMethodArgumentResolver (org.springframework.web.method.support.HandlerMethodArgumentResolver)3 ModelAttributeMethodProcessor (org.springframework.web.method.annotation.ModelAttributeMethodProcessor)2 HandlerMethod (org.springframework.web.method.HandlerMethod)1 ErrorsMethodArgumentResolver (org.springframework.web.method.annotation.ErrorsMethodArgumentResolver)1 ExpressionValueMethodArgumentResolver (org.springframework.web.method.annotation.ExpressionValueMethodArgumentResolver)1 RequestHeaderMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestHeaderMapMethodArgumentResolver)1 RequestHeaderMethodArgumentResolver (org.springframework.web.method.annotation.RequestHeaderMethodArgumentResolver)1 RequestParamMapMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMapMethodArgumentResolver)1 RequestParamMethodArgumentResolver (org.springframework.web.method.annotation.RequestParamMethodArgumentResolver)1 SessionStatusMethodArgumentResolver (org.springframework.web.method.annotation.SessionStatusMethodArgumentResolver)1 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)1 FlashMap (org.springframework.web.servlet.FlashMap)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1