Polishing the MVC sections of the reference manual.

This commit is contained in:
Sam Brannen 2009-10-20 21:56:22 +00:00
parent ee8ed4e410
commit a789bf2f1e
2 changed files with 29 additions and 44 deletions

View File

@ -2559,15 +2559,6 @@ background=/themes/cool/img/coolBg.jpg</programlisting>
<programlisting language="xml">&lt;bean id="multipartResolver" <programlisting language="xml">&lt;bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt; class="org.springframework.web.multipart.commons.CommonsMultipartResolver"&gt;
<lineannotation>&lt;!-- one of the properties available; the maximum file size in bytes --&gt;</lineannotation>
&lt;property name="maxUploadSize" value="100000"/&gt;
&lt;/bean&gt;</programlisting>
<para>This example uses the
<classname>CosMultipartResolver</classname>:</para>
<programlisting language="xml">&lt;bean id="multipartResolver" class="org.springframework.web.multipart.cos.CosMultipartResolver"&gt;
<lineannotation>&lt;!-- one of the properties available; the maximum file size in bytes --&gt;</lineannotation> <lineannotation>&lt;!-- one of the properties available; the maximum file size in bytes --&gt;</lineannotation>
&lt;property name="maxUploadSize" value="100000"/&gt; &lt;property name="maxUploadSize" value="100000"/&gt;
&lt;/bean&gt;</programlisting> &lt;/bean&gt;</programlisting>
@ -2575,9 +2566,7 @@ background=/themes/cool/img/coolBg.jpg</programlisting>
<para>Of course you also need to put the appropriate jars in your <para>Of course you also need to put the appropriate jars in your
classpath for the multipart resolver to work. In the case of the classpath for the multipart resolver to work. In the case of the
<classname>CommonsMultipartResolver</classname>, you need to use <classname>CommonsMultipartResolver</classname>, you need to use
<literal>commons-fileupload.jar</literal>; in the case of the <literal>commons-fileupload.jar</literal>.</para>
<classname>CosMultipartResolver</classname>, use
<literal>cos.jar</literal>.</para>
<para>When the Spring <classname>DispatcherServlet</classname> detects a <para>When the Spring <classname>DispatcherServlet</classname> detects a
multi-part request, it activates the resolver that has been declared in multi-part request, it activates the resolver that has been declared in
@ -2596,7 +2585,7 @@ background=/themes/cool/img/coolBg.jpg</programlisting>
<para>After the <classname>MultipartResolver</classname> completes its <para>After the <classname>MultipartResolver</classname> completes its
job, the request is processed like any other. To use it<!--to use what?-->, job, the request is processed like any other. To use it<!--to use what?-->,
you create a form with an upload field (see immediately below) that will you create a form with an upload field (see immediately below) that will
allow the user to upload a form, then let Spring bind the file onto your allow the user to upload a form. Then let Spring bind the file onto your
form (backing object). <!--I reworded because it sounded like you refer twice to creating a form. Where in example do you *let* Spring bind the file? Clarify.--><!--Does reader know what a backing object refers to?--></para> form (backing object). <!--I reworded because it sounded like you refer twice to creating a form. Where in example do you *let* Spring bind the file? Clarify.--><!--Does reader know what a backing object refers to?--></para>
<programlisting language="xml">&lt;html&gt; <programlisting language="xml">&lt;html&gt;
@ -2660,25 +2649,25 @@ background=/themes/cool/img/coolBg.jpg</programlisting>
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException errors) throws ServletException, IOException { Object command, BindException errors) throws ServletException, IOException {
<lineannotation> // cast the bean</lineannotation> <lineannotation>// cast the bean</lineannotation>
FileUploadBean bean = (FileUploadBean) command; FileUploadBean bean = (FileUploadBean) command;
<lineannotation> let's see if there's content there</lineannotation> <lineannotation>// let's see if there's content there</lineannotation>
byte[] file = bean.getFile(); byte[] file = bean.getFile();
if (file == null) { if (file == null) {
<lineannotation> // hmm, that's strange, the user did not upload anything</lineannotation> <lineannotation>// hmm, that's strange, the user did not upload anything</lineannotation>
} }
<lineannotation> // well, let's do nothing with the bean for now and return</lineannotation> <lineannotation>// well, let's do nothing with the bean for now and return</lineannotation>
return super.onSubmit(request, response, command, errors); return super.onSubmit(request, response, command, errors);
} }
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
throws ServletException { throws ServletException {
// to actually be able to convert Multipart instance to byte[] <lineannotation>// to actually be able to convert Multipart instance to byte[]</lineannotation>
// we have to register a custom editor <lineannotation>// we have to register a custom editor</lineannotation>
binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor()); binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
// now Spring knows how to handle multipart object and convert them <lineannotation>// now Spring knows how to handle multipart objects and convert them</lineannotation>
} }
} }
@ -2711,16 +2700,16 @@ public class FileUploadBean {
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException errors) throws ServletException, IOException { Object command, BindException errors) throws ServletException, IOException {
<lineannotation> // cast the bean</lineannotation> <lineannotation>// cast the bean</lineannotation>
FileUploadBean bean = (FileUploadBean) command; FileUploadBean bean = (FileUploadBean) command;
<lineannotation> let's see if there's content there</lineannotation> <lineannotation>// let's see if there's content there</lineannotation>
String file = bean.getFile(); String file = bean.getFile();
if (file == null) { if (file == null) {
<lineannotation> // hmm, that's strange, the user did not upload anything</lineannotation> <lineannotation>// hmm, that's strange, the user did not upload anything</lineannotation>
} }
<lineannotation> // well, let's do nothing with the bean for now and return</lineannotation> <lineannotation>// well, let's do nothing with the bean for now and return</lineannotation>
return super.onSubmit(request, response, command, errors); return super.onSubmit(request, response, command, errors);
} }
@ -2762,16 +2751,16 @@ public class FileUploadBean {
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException errors) throws ServletException, IOException { Object command, BindException errors) throws ServletException, IOException {
<lineannotation> // cast the bean</lineannotation> <lineannotation>// cast the bean</lineannotation>
FileUploadBean bean = (FileUploadBean) command; FileUploadBean bean = (FileUploadBean) command;
<lineannotation> let's see if there's content there</lineannotation> <lineannotation> let's see if there's content there</lineannotation>
MultipartFile file = bean.getFile(); MultipartFile file = bean.getFile();
if (file == null) { if (file == null) {
<lineannotation> // hmm, that's strange, the user did not upload anything</lineannotation> <lineannotation>// hmm, that's strange, the user did not upload anything</lineannotation>
} }
<lineannotation> // well, let's do nothing with the bean for now and return</lineannotation> <lineannotation>// well, let's do nothing with the bean for now and return</lineannotation>
return super.onSubmit(request, response, command, errors); return super.onSubmit(request, response, command, errors);
} }
} }

View File

@ -72,7 +72,7 @@ productList.url=/WEB-INF/jsp/productlist.jsp</programlisting>
<para>When using the Java Standard Tag Library you must use a special <para>When using the Java Standard Tag Library you must use a special
view class, the <classname>JstlView</classname>, as JSTL needs some view class, the <classname>JstlView</classname>, as JSTL needs some
preparation before things such as the i18N features will work.</para> preparation before things such as the I18N features will work.</para>
</section> </section>
<section id="view-jsp-tags"> <section id="view-jsp-tags">
@ -86,8 +86,8 @@ productList.url=/WEB-INF/jsp/productlist.jsp</programlisting>
escaping of characters.</para> escaping of characters.</para>
<para>The tag library descriptor (TLD) is included in the <filename <para>The tag library descriptor (TLD) is included in the <filename
class="libraryfile">spring.jar</filename> as well in the distribution class="libraryfile">org.springframework.web.servlet-3.0.0.RELEASE.jar</filename>.
itself. Further information about the individual tags can be found in Further information about the individual tags can be found in
the appendix entitled <xref linkend="spring.tld" />.</para> the appendix entitled <xref linkend="spring.tld" />.</para>
</section> </section>
@ -115,7 +115,8 @@ productList.url=/WEB-INF/jsp/productlist.jsp</programlisting>
<title>Configuration</title> <title>Configuration</title>
<para>The form tag library comes bundled in <para>The form tag library comes bundled in
<literal>spring.jar</literal>. The library descriptor is called <literal>org.springframework.web.servlet-3.0.0.RC1.jar</literal>.
The library descriptor is called
<literal>spring-form.tld</literal>.</para> <literal>spring-form.tld</literal>.</para>
<para>To use the tags from this library, add the following directive <para>To use the tags from this library, add the following directive
@ -813,7 +814,7 @@ public String deletePet(@PathVariable int ownerId, @PathVariable int petId) {
dependencies included in your project. The following is the list of dependencies included in your project. The following is the list of
dependencies you need.</para> dependencies you need.</para>
<para><itemizedlist spacing="compact"> <itemizedlist spacing="compact">
<listitem> <listitem>
<para><literal>Tiles version 2.0.4 or higher</literal></para> <para><literal>Tiles version 2.0.4 or higher</literal></para>
</listitem> </listitem>
@ -829,10 +830,8 @@ public String deletePet(@PathVariable int ownerId, @PathVariable int petId) {
<listitem> <listitem>
<para><literal>Commons Logging</literal></para> <para><literal>Commons Logging</literal></para>
</listitem> </listitem>
</itemizedlist></para> </itemizedlist>
<para>These dependencies are all available in the Spring
distribution.</para>
</section> </section>
<section id="view-tiles-integrate"> <section id="view-tiles-integrate">
@ -910,12 +909,12 @@ findOwnersForm.url=/WEB-INF/jsp/findOwners.jsp
<para>As you can see, when using the <para>As you can see, when using the
<classname>ResourceBundleViewResolver</classname>, you can easily mix <classname>ResourceBundleViewResolver</classname>, you can easily mix
different view technologies.</para> different view technologies.</para>
</section>
<para>Note that the <classname>TilesView</classname> class for Tiles 2 <para>Note that the <classname>TilesView</classname> class for Tiles 2
supports JSTL (the JSP Standard Tag Library) out of the box, whereas supports JSTL (the JSP Standard Tag Library) out of the box, whereas
there is a separate <classname>TilesJstlView</classname> subclass in the there is a separate <classname>TilesJstlView</classname> subclass in the
Tiles 1.x support.</para> Tiles 1.x support.</para>
</section>
<section id="view-tiles-preparer"> <section id="view-tiles-preparer">
<title><classname>SimpleSpringPreparerFactory</classname> and <title><classname>SimpleSpringPreparerFactory</classname> and
@ -990,10 +989,7 @@ findOwnersForm.url=/WEB-INF/jsp/findOwners.jsp
found by a Java EE server and added to the classpath for your application. found by a Java EE server and added to the classpath for your application.
It is of course assumed that you already have the <filename It is of course assumed that you already have the <filename
class="libraryfile">spring.jar</filename> in your <filename class="libraryfile">spring.jar</filename> in your <filename
class="directory">'WEB-INF/lib'</filename> directory too! The latest class="directory">'WEB-INF/lib'</filename> directory too! If you make use of
stable Velocity, FreeMarker and Commons Collections jars are supplied
with the Spring framework and can be copied from the relevant <filename
class="libraryfile">/lib/</filename> sub-directories. If you make use of
Spring's 'dateToolAttribute' or 'numberToolAttribute' in your Velocity Spring's 'dateToolAttribute' or 'numberToolAttribute' in your Velocity
views, you will also need to include the <filename views, you will also need to include the <filename
class="libraryfile">velocity-tools-generic-1.x.jar</filename></para> class="libraryfile">velocity-tools-generic-1.x.jar</filename></para>