Add reference guide section on JSF file uploads

Issue: SWF-1482
This commit is contained in:
Rossen Stoyanchev
2013-01-30 09:27:34 -05:00
parent 9f17ee57cc
commit 8974263f8c
2 changed files with 68 additions and 4 deletions

View File

@@ -410,10 +410,13 @@ public class PrintBoardingPassAction extends AbstractAction {
HTML form is configured with <code>enctype="multipart/form-data"</code>, you can easily handle the file upload in a
transition action.
</para>
<para>
Note that the File Upload example below below is not relevant when using Web Flow with JSF.
Check the documentation of your JSF component library to see what file upload components it provides.
</para>
<note>
<para>
The file upload example below below is not relevant when using Web
Flow with JSF. See <xref linkend="spring-faces-file-upload" />
for details of how to upload files using JSF.
</para>
</note>
<para>
Given a form such as:
</para>

View File

@@ -699,6 +699,67 @@
</programlisting>
</sect2>
<sect2 id="spring-faces-file-upload">
<title>Handling File Uploads with JSF</title>
<para>Most JSF component providers include some form of 'file upload' component. Generally when working
with these components JSF must take complete control of parsing multi-part requests and Spring MVC's
<code>MultipartResolver</code> cannot be used.</para>
<para>Spring Web Flow has been tested with file upload components from PrimeFaces and RichFaces. Check the
documentation of your JSF component library for other providers to see how to configure file upload.</para>
<sect3>
<title>File Uploads with PrimeFaces</title>
<para>PrimeFaces provides a <code>&lt;p:fileUpload&gt;</code> component for uploading files. In order
to use the component you need to configure the <code>org.primefaces.webapp.filter.FileUploadFilter</code>
servlet filter. The filter needs to be configured against Spring MVC's
<code>DispatcherServlet</code> in your <code>web.xml</code>:</para>
<programlisting language="xml"><![CDATA[<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
</filter-mapping>]]>
</programlisting>
<para>For more details refer to the
<ulink url="http://primefaces.org/documentation.html">PrimeFaces documentation</ulink>.</para>
</sect3>
<sect3>
<title>File Uploads with RichFaces</title>
<para>RichFaces provides a <code>&lt;rich:fileUpload&gt;</code> component for uploading files. No
special configuration is required to use the component, however, you will need to perform
some additional steps in your <code>fileUploadListener</code>.</para>
<para>Here is some typical XHTML markup. In this example the <code>fileUploadBean</code> refers
to Spring singleton bean.</para>
<programlisting language="xml"><![CDATA[<rich:fileUpload id="upload"
fileUploadListener="#{fileUploadBean.listener}"
acceptedTypes="jpg, gif, png, bmp">
</rich:fileUpload>]]></programlisting>
<para>Within your <code>fileUploadBean</code> you need to tell Web Flow that the response has been
handled and that it should not attempt any redirects. The <interfacename>org.springframework.webflow.context.ExternalContext</interfacename>
interface provides a <code>recordResponseComplete()</code> for just such purposes.</para>
<para>In addition, it is imperative that some partial response data is returned to the client. If your
<code>&lt;rich:fileUpload&gt;</code> component does not specify a <code>render</code> attribute you
may need to call <code>processPartial(PhaseId.RENDER_RESPONSE)</code> on the JSF
<code>PartialViewContext</code>.</para>
<programlisting language="java">public class FileUploadBean {
public void listener(FileUploadEvent event) throws Exception{
FacesContext.getCurrentInstance().getPartialViewContext().processPartial(PhaseId.RENDER_RESPONSE);
ExternalContextHolder.getExternalContext().recordResponseComplete();
UploadedFile file = event.getUploadedFile();
// Do something with the file
}
}</programlisting>
<para>For more details refer to the
<ulink url="http://www.jboss.org/richfaces/docs">RichFaces documentation</ulink>.</para>
</sect3>
</sect2>
<sect2 id="spring-faces-ajax-events-jsf12">
<title>Handling Ajax Events In JSF 1.2</title>