SPR-2692 Update mvc chapter with URI template support in redirect: view names

master
Rossen Stoyanchev 14 years ago
parent d14d82612d
commit 57c757afc5
  1. 3
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfiguration.java
  2. 2
      org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java
  3. 36
      spring-framework-reference/src/mvc.xml

@ -302,8 +302,7 @@ class WebMvcConfiguration implements ApplicationContextAware, ServletContextAwar
private HandlerExceptionResolver createExceptionHandlerExceptionResolver() throws Exception { private HandlerExceptionResolver createExceptionHandlerExceptionResolver() throws Exception {
ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver(); ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
resolver.setOrder(0);
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
configurers.configureMessageConverters(converters); configurers.configureMessageConverters(converters);
if (converters.size() == 0) { if (converters.size() == 0) {

@ -164,7 +164,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
this.messageConverters = messageConverters; this.messageConverters = messageConverters;
} }
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() {
if (argumentResolvers == null) { if (argumentResolvers == null) {
argumentResolvers = new HandlerMethodArgumentResolverComposite(); argumentResolvers = new HandlerMethodArgumentResolverComposite();
argumentResolvers.addResolvers(customArgumentResolvers); argumentResolvers.addResolvers(customArgumentResolvers);

@ -2158,18 +2158,31 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
<para>The <classname>RedirectView</classname> issues an <para>The <classname>RedirectView</classname> issues an
<literal>HttpServletResponse.sendRedirect()</literal> call that <literal>HttpServletResponse.sendRedirect()</literal> call that
returns to the client browser as an HTTP redirect. <!--Does preceding happen after what happens in first paragraph? Clarify sequence of events.-->All returns to the client browser as an HTTP redirect.
model attributes are exposed as HTTP query parameters. This means that All model attributes are considered to be exposed as either URI template variables first,
the model must contain only objects (generally Strings or objects assuming the URL is a URI template such as <code>/account/{number}</code>,
converted to a String representation), which can be readily converted or as HTTP query parameters second. By default String and primitive model attributes
to a textual HTTP query parameter.</para> are eligible to be exposed this way. However, this behavior can be extended by
sub-classing RedirectView. Also consider that <code>@PathVariable</code>-annotated
method arguments are automatically added to the model, which is convenient when
redirecting to the same URL using a different HTTP method. For example:</para>
<programlisting language="java">@RequestMapping(value = "/files/{path}", method = RequestMethod.POST)
public String upload(@PathVariable String path, ...) {
// ...
return "redirect:files/{path};
}
@RequestMapping(value = "/files/{path}", method = RequestMethod.GET)
public void get(@PathVariable String path, ...) {
// ...
}</programlisting>
<para>If you use <classname>RedirectView</classname> and the view is <para>If you use <classname>RedirectView</classname> and the view is
created by the controller itself, it is recommended that you configure created by the controller itself, it is recommended that you configure
the redirect URL to be injected into the controller so that it is not the redirect URL to be injected into the controller so that it is not
baked into the controller but configured in the context along with the baked into the controller but configured in the context along with the
view names. <!--I revised sentence because it sounds like something you need to do. Also reworded next heading to say what it's about. If not correct,--><!--reword.-->The view names. The next section discusses this process.</para>
next section discusses this process.</para>
</section> </section>
<section id="mvc-redirecting-redirect-prefix"> <section id="mvc-redirecting-redirect-prefix">
@ -2194,13 +2207,10 @@ public class TimeBasedAccessInterceptor extends HandlerInterceptorAdapter {
<para>The net effect is the same as if the controller had returned a <para>The net effect is the same as if the controller had returned a
<classname>RedirectView</classname>, but now the controller itself can <classname>RedirectView</classname>, but now the controller itself can
simply operate in terms of logical view names. A logical view name simply operate in terms of logical view names. A logical view name
such as <literal>redirect:/my/response/controller.html</literal> will such as <literal>redirect:/myapp/some/resource</literal> will
redirect relative to the current servlet context, while a name such as redirect relative to the current servlet context, while a name such as
<literal>redirect:http://myhost.com/some/arbitrary/path.html</literal> <literal>redirect:http://myhost.com/some/arbitrary/path</literal>
will redirect to an absolute URL. The important thing is that, as long will redirect to an absolute URL.</para>
as this redirect view name is injected into the controller like any
other logical view name, the controller is not even aware that
redirection is happening.</para>
</section> </section>
<section id="mvc-redirecting-forward-prefix"> <section id="mvc-redirecting-forward-prefix">

Loading…
Cancel
Save