Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think it is possible to use multiple file upload using the standard JSF 2.2 using the passthrough tag.</p> <h3>Step 1:</h3> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"&gt; ... &lt;h:form id="form" enctype="multipart/form-data"&gt; &lt;h:inputFile id="file" value="#{fileUploadBean.uploadedFile}" pt:multiple="multiple" /&gt; ... </code></pre> <h3>Step 2:</h3> <p>The JSF renderer class <a href="https://java.net/projects/mojarra/sources/svn/content/tags/2.2.9/jsf-ri/src/main/java/com/sun/faces/renderkit/html_basic/FileRenderer.java?rev=14185" rel="nofollow">FileRenderer</a> for the <code>javax.faces.File</code> type of the <code>javax.faces.Input</code> family of components doesn't handle this case correctly.</p> <p>Instead, as it iterates through the parts of the form, it just overwrites the preceding part with each file in the uploaded collection.</p> <p>I think a better strategy is to always have the value of the component be a <code>List&lt;Part&gt;</code> instead of just <code>Part</code> as suggested <a href="https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1197" rel="nofollow">here</a> and implemented <a href="https://www.packtpub.com/books/content/uploading-multiple-files" rel="nofollow">here</a>.</p> <h3>Step 3:</h3> <p>The last thing to make it work is to configure such modified multiple file renderer class in <code>faces-config.xml</code> adding the following to the <code>&lt;faces-config&gt;</code> root element: </p> <pre><code>&lt;render-kit&gt; &lt;renderer&gt; &lt;description&gt;Multiple File Renderer&lt;/description&gt; &lt;component-family&gt;javax.faces.Input&lt;/component-family&gt; &lt;renderer-type&gt;javax.faces.File&lt;/renderer-type&gt; &lt;renderer-class&gt;com.example.MultipleFileRenderer&lt;/renderer-class&gt; &lt;/renderer&gt; &lt;/render-kit&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload