SPR-8801 Set ignoreDefaultModelOnRedirect=false in MVC namespace and Java config.
This commit is contained in:
parent
cd2fee035a
commit
8889284517
|
@ -20,6 +20,7 @@ Changes in version 3.1 RC2 (2011-11-15)
|
|||
* Fix issue in SimpleMappingExceptionResolver causing exception when setting "statusCodes" property
|
||||
* The Form input tag allows type values other than "text" such as HTML5-specific types.
|
||||
* The Form hidden tag supports "disabled" attribute
|
||||
* Add ignoreDefaultModelOnRedirect attribute to <mvc:annotation-driven/>
|
||||
|
||||
Changes in version 3.1 RC1 (2011-10-11)
|
||||
---------------------------------------
|
||||
|
|
|
@ -158,13 +158,16 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
|||
ManagedList<?> messageConverters = getMessageConverters(element, source, parserContext);
|
||||
ManagedList<?> argumentResolvers = getArgumentResolvers(element, source, parserContext);
|
||||
ManagedList<?> returnValueHandlers = getReturnValueHandlers(element, source, parserContext);
|
||||
|
||||
|
||||
RootBeanDefinition methodAdapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
methodAdapterDef.setSource(source);
|
||||
methodAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
methodAdapterDef.getPropertyValues().add("webBindingInitializer", bindingDef);
|
||||
methodAdapterDef.getPropertyValues().add("messageConverters", messageConverters);
|
||||
methodAdapterDef.getPropertyValues().add("ignoreDefaultModelOnRedirect", true);
|
||||
if (element.hasAttribute("ignoreDefaultModelOnRedirect")) {
|
||||
Boolean ignoreDefaultModel = Boolean.valueOf(element.getAttribute("ignoreDefaultModelOnRedirect"));
|
||||
methodAdapterDef.getPropertyValues().add("ignoreDefaultModelOnRedirect", ignoreDefaultModel);
|
||||
}
|
||||
if (argumentResolvers != null) {
|
||||
methodAdapterDef.getPropertyValues().add("customArgumentResolvers", argumentResolvers);
|
||||
}
|
||||
|
|
|
@ -291,7 +291,6 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
|
|||
adapter.setWebBindingInitializer(webBindingInitializer);
|
||||
adapter.setCustomArgumentResolvers(argumentResolvers);
|
||||
adapter.setCustomReturnValueHandlers(returnValueHandlers);
|
||||
adapter.setIgnoreDefaultModelOnRedirect(true);
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.springframework.http.converter.HttpMessageConverter;
|
|||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.MethodFilter;
|
||||
|
@ -372,16 +371,17 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter i
|
|||
}
|
||||
|
||||
/**
|
||||
* A controller can use the "default" {@link Model} in rendering and
|
||||
* redirect scenarios. Alternatively, it can use {@link RedirectAttributes}
|
||||
* to provide attributes for a redirect scenario.
|
||||
* <p>When this flag is set to {@code true}, the "default" model is never
|
||||
* used in a redirect even if the controller method doesn't explicitly
|
||||
* declare a RedirectAttributes argument.
|
||||
* <p>When set to {@code false}, the "default" model may be used in a
|
||||
* redirect if the controller method doesn't explicitly declare a
|
||||
* By default the content of the "default" model is used both during
|
||||
* rendering and redirect scenarios. Alternatively a controller method
|
||||
* can declare a {@link RedirectAttributes} argument and use it to provide
|
||||
* attributes for a redirect.
|
||||
* <p>Setting this flag to {@code true} guarantees the "default" model is
|
||||
* never used in a redirect scenario even if a RedirectAttributes argument
|
||||
* is not declared. Setting it to {@code false} means the "default" model
|
||||
* may be used in a redirect if the controller method doesn't declare a
|
||||
* RedirectAttributes argument.
|
||||
* <p>The default setting is {@code false}.
|
||||
* <p>The default setting is {@code false} but new applications should
|
||||
* consider setting it to {@code true}.
|
||||
* @see RedirectAttributes
|
||||
*/
|
||||
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) {
|
||||
|
|
|
@ -134,6 +134,17 @@
|
|||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ignoreDefaultModelOnRedirect" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
By default the content of the "default" model is used both during rendering and redirect scenarios.
|
||||
Alternatively a controller method can declare a RedirectAttributes argument and use it to provide attributes for a redirect.
|
||||
Setting this flag to true ensures the "default" model is never used in a redirect scenario even if a RedirectAttributes argument is not declared.
|
||||
Setting it to false means the "default" model may be used in a redirect if the controller method doesn't declare a RedirectAttributes argument.
|
||||
The default setting is false but new applications should consider setting it to true.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
|||
MessageCodesResolver resolver = ((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
|
||||
assertNotNull(resolver);
|
||||
assertEquals(TestMessageCodesResolver.class, resolver.getClass());
|
||||
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -34,6 +34,7 @@ import javax.validation.constraints.NotNull;
|
|||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
@ -109,6 +110,7 @@ public class MvcNamespaceTests {
|
|||
|
||||
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||
|
||||
List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
|
||||
assertTrue(messageConverters.size() > 0);
|
||||
|
@ -166,6 +168,7 @@ public class MvcNamespaceTests {
|
|||
|
||||
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||
|
||||
// default web binding initializer behavior test
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
@ -322,7 +325,7 @@ public class MvcNamespaceTests {
|
|||
ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
|
||||
assertEquals("style", interceptor2.getParamName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testViewControllers() throws Exception {
|
||||
loadBeanDefinitions("mvc-config-view-controllers.xml", 14);
|
||||
|
@ -346,7 +349,7 @@ public class MvcNamespaceTests {
|
|||
|
||||
SimpleUrlHandlerMapping mapping2 = appContext.getBean(SimpleUrlHandlerMapping.class);
|
||||
assertNotNull(mapping2);
|
||||
|
||||
|
||||
SimpleControllerHandlerAdapter adapter = appContext.getBean(SimpleControllerHandlerAdapter.class);
|
||||
assertNotNull(adapter);
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public class WebMvcConfigurationSupportTests {
|
|||
assertNotNull(validator);
|
||||
assertTrue(validator instanceof LocalValidatorFactoryBean);
|
||||
|
||||
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
|
||||
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
|
||||
|
||||
<mvc:annotation-driven validator="validator"/>
|
||||
<mvc:annotation-driven validator="validator" ignoreDefaultModelOnRedirect="true" />
|
||||
|
||||
<bean id="validator" class="org.springframework.web.servlet.config.MvcNamespaceTests$TestValidator" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue