Note that there are some explanatory texts on larger screens.

plurals
  1. POprimefaces FileUploadEvent returns null
    text
    copied!<p>I'm trying to upload a file with primefaces fileuploader but it returns null,</p> <p>addPhotos.xhtml :</p> <pre><code>&lt;h:form id="importDevicesForm" enctype="multipart/form-data"&gt; &lt;h:outputText value="Photo :" /&gt; &lt;p:fileUpload id="scriptUpload" widgetVar="importDevicesWidget" fileUploadListener="#{docBean.file}" auto="true" label="Choisir une photo.." mode="advanced" allowTypes="/(\.|\/)(gif|jpe?g|png)$/"&gt; &lt;h:outputText value="Description :" /&gt; &lt;p:commandButton value="Ajouter" action="#{docBean.ajouter_photo}"/&gt; &lt;/h:form&gt; </code></pre> <p>My backing bean : I want to upload the file an use an outputStream to write the file in filesystem. </p> <pre><code>@ManagedBean(name = "docBean") @SessionScoped public class DocumentBean implements Serializable { private static final long serialVersionUID = 1L; private UploadedFile file = null; private File doc; private InfoDAO docdao = new InfoDaoImpl(); public UploadedFile getFile() { return file; } public void setFile(FileUploadEvent event) { this.file = event.getFile(); } public String ajouter_photo() throws SQLException, IOException { System.out.println("call"); File targetFolder = new File("C:/images/upload"); InputStream inputStream = this.file.getInputstream(); OutputStream out = new FileOutputStream(new File(targetFolder, this.file.getFileName())); int read = 0; byte[] bytes = new byte[1024]; while ((read = inputStream.read(bytes)) != -1) { out.write(bytes, 0, read); } inputStream.close(); out.flush(); out.close(); Document f = new Document(); f.setDescription(targetFolder.getPath()); docdao.Ajouter_info(f); } </code></pre> <p>here is the exception</p> <pre><code>Avertissement: #{docBean.ajouter_photo}: java.lang.NullPointerException javax.faces.FacesException: #{docBean.ajouter_photo}: java.lang.NullPointerException at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:117) </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