Note that there are some explanatory texts on larger screens.

plurals
  1. POp:fileUpload calls bean constructor for each file
    primarykey
    data
    text
    <p>I'm trying to use <code>&lt;p:fileUpload&gt;</code> to upload a file. Here's the view: </p> <pre><code> &lt;h:form enctype="multipart/form-data"&gt; &lt;p:growl id="messages" showDetail="true" /&gt; &lt;p:fileUpload fileUploadListener="#{viewscopedBean.handleFileUpload}" mode="advanced" dragDropSupport="true" multiple="true" update="messages" /&gt; &lt;/h:form&gt; </code></pre> <p>Bean:</p> <pre><code>@ManagedBean @ViewScoped public class ViewscopedBean implements Serializable{ private List&lt;UploadedFile&gt; uploadedFiles; //to remember which files have been uploaded public ViewscopedBean() { super(); System.out.println("@constructor"); uploadedFiles = new ArrayList&lt;UploadedFile&gt;(); } public void handleFileUpload(FileUploadEvent event) { System.out.println("! HANDLE FILE UPLOAD !"); // do something } public List&lt;UploadedFile&gt; getUploadedFiles() { return uploadedFiles; } public void setUploadedFiles(List&lt;UploadedFile&gt; uploadedFiles) { this.uploadedFiles = uploadedFiles; } } </code></pre> <p><code>web.xml</code></p> <pre><code>&lt;filter&gt; &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt; &lt;filter-class&gt; org.primefaces.webapp.filter.FileUploadFilter &lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;thresholdSize&lt;/param-name&gt; &lt;param-value&gt;512000&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;PrimeFaces FileUpload Filter&lt;/filter-name&gt; &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt; &lt;/filter-mapping&gt; </code></pre> <p>When I click on the <code>upload button</code>, the progressbar is filling up to 100% (like it does something), but then the page is reloaded (constructor is being called for every uploaded file) - the <code>handleFileUpload</code> method is never called.</p> <p>There aren't any errors or warnings, it just doesn't do what it should. I have JSF 2.0 and use Primefaces 4, maybe there is a problem?</p> <p>How is this caused and how can I solve it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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