Skip to content

Commit 857faec

Browse files
committed
SPR-7103 - Added more detailed documentation on ordering of model attribute and BindingResult.
1 parent 5b420e2 commit 857faec

File tree

1 file changed

+26
-4
lines changed
  • spring-framework-reference/src

1 file changed

+26
-4
lines changed

spring-framework-reference/src/mvc.xml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,8 @@ public class RelativePathUriTemplateController {
949949

950950
<para>Handler methods that are annotated with
951951
<classname>@RequestMapping</classname> can have very flexible
952-
signatures. They may have arguments of the following types, in
953-
arbitrary order (except for validation results, which need to follow
954-
right after the corresponding command object, if desired): <!--Reword preceding sentence to clarify, make it a complete sentence and no parentheses: first it says validation results *must*--><!--immediately follow command object, but then it says *if desired*. Clarify what must happen if what is desired. And are validation --><!-- results a type of argument? Relate to the sentence that precedes it.-->
955-
<itemizedlist>
952+
signatures. Most of them can be used in arbitrary order (see below for
953+
more details). <itemizedlist>
956954
<listitem>
957955
<para>Request or response objects (Servlet API). Choose any
958956
specific request or response type, for example
@@ -1084,6 +1082,30 @@ public class RelativePathUriTemplateController {
10841082
</listitem>
10851083
</itemizedlist></para>
10861084

1085+
<para>The <interfacename>Errors</interfacename> or
1086+
<interfacename>BindingResult</interfacename> parameters have to follow
1087+
the model object that is being bound immediately as the method
1088+
signature might have more that one model object and Spring will create
1089+
a separate <interfacename>BindingResult</interfacename> instance for
1090+
each of them so the following sample won't work:</para>
1091+
1092+
<example>
1093+
<title>Invalid ordering of BindingResult and @ModelAttribute</title>
1094+
1095+
<programlisting lang="java">@RequestMapping(method = RequestMethod.POST)
1096+
public String processSubmit(<emphasis role="bold">@ModelAttribute("pet") Pet pet</emphasis>,
1097+
Model model, <emphasis role="bold">BindingResult result</emphasis>) { … }</programlisting>
1098+
1099+
<para>Note, that there is a <interfacename>Model</interfacename>
1100+
parameter in between <classname>Pet</classname> and
1101+
<interfacename>BindingResult</interfacename>. To get this working
1102+
you have to reorder the parameters as follows:</para>
1103+
1104+
<programlisting lang="java">@RequestMapping(method = RequestMethod.POST)
1105+
public String processSubmit(<emphasis role="bold">@ModelAttribute("pet") Pet pet</emphasis>,
1106+
<emphasis role="bold">BindingResult result</emphasis>, Model model) { … }</programlisting>
1107+
</example>
1108+
10871109
<para>The following return types are supported for handler methods:
10881110
<itemizedlist>
10891111
<listitem>

0 commit comments

Comments
 (0)