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
|
* 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 input tag allows type values other than "text" such as HTML5-specific types.
|
||||||
* The Form hidden tag supports "disabled" attribute
|
* The Form hidden tag supports "disabled" attribute
|
||||||
|
* Add ignoreDefaultModelOnRedirect attribute to <mvc:annotation-driven/>
|
||||||
|
|
||||||
Changes in version 3.1 RC1 (2011-10-11)
|
Changes in version 3.1 RC1 (2011-10-11)
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,10 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser {
|
||||||
methodAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
methodAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||||
methodAdapterDef.getPropertyValues().add("webBindingInitializer", bindingDef);
|
methodAdapterDef.getPropertyValues().add("webBindingInitializer", bindingDef);
|
||||||
methodAdapterDef.getPropertyValues().add("messageConverters", messageConverters);
|
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) {
|
if (argumentResolvers != null) {
|
||||||
methodAdapterDef.getPropertyValues().add("customArgumentResolvers", argumentResolvers);
|
methodAdapterDef.getPropertyValues().add("customArgumentResolvers", argumentResolvers);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,6 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
|
||||||
adapter.setWebBindingInitializer(webBindingInitializer);
|
adapter.setWebBindingInitializer(webBindingInitializer);
|
||||||
adapter.setCustomArgumentResolvers(argumentResolvers);
|
adapter.setCustomArgumentResolvers(argumentResolvers);
|
||||||
adapter.setCustomReturnValueHandlers(returnValueHandlers);
|
adapter.setCustomReturnValueHandlers(returnValueHandlers);
|
||||||
adapter.setIgnoreDefaultModelOnRedirect(true);
|
|
||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||||
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
|
||||||
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
|
import org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter;
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.ReflectionUtils.MethodFilter;
|
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
|
* By default the content of the "default" model is used both during
|
||||||
* redirect scenarios. Alternatively, it can use {@link RedirectAttributes}
|
* rendering and redirect scenarios. Alternatively a controller method
|
||||||
* to provide attributes for a redirect scenario.
|
* can declare a {@link RedirectAttributes} argument and use it to provide
|
||||||
* <p>When this flag is set to {@code true}, the "default" model is never
|
* attributes for a redirect.
|
||||||
* used in a redirect even if the controller method doesn't explicitly
|
* <p>Setting this flag to {@code true} guarantees the "default" model is
|
||||||
* declare a RedirectAttributes argument.
|
* never used in a redirect scenario even if a RedirectAttributes argument
|
||||||
* <p>When set to {@code false}, the "default" model may be used in a
|
* is not declared. Setting it to {@code false} means the "default" model
|
||||||
* redirect if the controller method doesn't explicitly declare a
|
* may be used in a redirect if the controller method doesn't declare a
|
||||||
* RedirectAttributes argument.
|
* 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
|
* @see RedirectAttributes
|
||||||
*/
|
*/
|
||||||
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) {
|
public void setIgnoreDefaultModelOnRedirect(boolean ignoreDefaultModelOnRedirect) {
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,17 @@
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</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:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
||||||
MessageCodesResolver resolver = ((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
|
MessageCodesResolver resolver = ((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
|
||||||
assertNotNull(resolver);
|
assertNotNull(resolver);
|
||||||
assertEquals(TestMessageCodesResolver.class, resolver.getClass());
|
assertEquals(TestMessageCodesResolver.class, resolver.getClass());
|
||||||
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.TypeMismatchException;
|
import org.springframework.beans.TypeMismatchException;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
|
|
@ -109,6 +110,7 @@ public class MvcNamespaceTests {
|
||||||
|
|
||||||
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
||||||
assertNotNull(adapter);
|
assertNotNull(adapter);
|
||||||
|
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||||
|
|
||||||
List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
|
List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
|
||||||
assertTrue(messageConverters.size() > 0);
|
assertTrue(messageConverters.size() > 0);
|
||||||
|
|
@ -166,6 +168,7 @@ public class MvcNamespaceTests {
|
||||||
|
|
||||||
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
|
||||||
assertNotNull(adapter);
|
assertNotNull(adapter);
|
||||||
|
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||||
|
|
||||||
// default web binding initializer behavior test
|
// default web binding initializer behavior test
|
||||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ public class WebMvcConfigurationSupportTests {
|
||||||
assertNotNull(validator);
|
assertNotNull(validator);
|
||||||
assertTrue(validator instanceof LocalValidatorFactoryBean);
|
assertTrue(validator instanceof LocalValidatorFactoryBean);
|
||||||
|
|
||||||
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
assertEquals(false, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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
|
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" />
|
<bean id="validator" class="org.springframework.web.servlet.config.MvcNamespaceTests$TestValidator" />
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue