title: j2ee primefaces fileupload file saving destination
body: <p>Today I've got a problem with the PrimeFaces FileUpload. It works nice, but the files are stored in JBoss' temporary directory so whenever I redeploy the application or just commit the sources to svn, all of the images I uploaded are gone. So I wanted to ask, whether there is a way to save the images to the "source" directory of the war project.</p>
  
  <p>My handleFileUpload method :</p>
  
  <pre><code>public String getUrlBase() {
      return FacesContext.getCurrentInstance().getExternalContext().getRealPath("//upload");
  }
  
  public void handleFileUpload(FileUploadEvent event) {
          new File(getUrlBase() + "/" + album.getId()).mkdirs();
          File result = new File(getUrlBase() + "/" + album.getId() + "/" + event.getFile().getFileName());
  
          try {
              FileOutputStream fileOutputStream = new FileOutputStream(result);
  
              byte[] buffer = new byte[BUFFER_SIZE];
  
              int bulk;
              InputStream inputStream = event.getFile().getInputstream();
              while (true) {
                  bulk = inputStream.read(buffer);
                  if (bulk &lt; 0) {
                      break;
                  }
                  fileOutputStream.write(buffer, 0, bulk);
                  fileOutputStream.flush();
              }
  
              fileOutputStream.close();
              inputStream.close();
  
              FacesMessage msg = new FacesMessage("Succesful",
                      event.getFile().getFileName() + " is uploaded.");
              FacesContext.getCurrentInstance().addMessage(null, msg);
  
          } catch (IOException e) {
              e.printStackTrace();
              FacesMessage error = new FacesMessage("The files were not uploaded!");
              FacesContext.getCurrentInstance().addMessage(null, error);
          }
      }
  </code></pre>
  
  <p>EDIT: another issue</p>
  
  <p>my view file:</p>
  
  <pre><code>&lt;h:form enctype="multipart/form-data" prependId="false"&gt;
          &lt;p:growl id="messages" showSummary="true" showDetail="true" /&gt;
          &lt;p:fileUpload fileUploadListener="#{photo.handleFileUpload}"
                        update="messages"  sizeLimit="1073741824"
                        multiple="true" label="choose" allowTypes="*.jpg;*.png;*.gif;"
                        description="Images" /&gt;
      &lt;/h:form&gt;
  </code></pre>
  
  <p>When I add update="messages" to the fileUpload I get</p>
  
  <pre><code>javax.servlet.ServletException: null source
  </code></pre>
  
  <p>whenever I try to just open the page with the fileUpload. Don't you know how to get rid of it?</p>