title: PrimeFaces p:fileUpload does not invoke method
body: <p>I'm trying to use PrimeFaces <code>&lt;p:fileUpload&gt;</code>. I have it setup, very much the same as <a href="http://www.primefaces.org/showcase/ui/fileUploadMultiple.jsf" rel="nofollow">the showcase example</a>, but it does not work. I never get the successful message. I get no errors or anything. </p>
  
  <p>Here's my <code>web.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &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;51200&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;uploadDirectory&lt;/param-name&gt;
              &lt;param-value&gt;C:\etc&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;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;faces/index.xhtml&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Here's the view:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:p="http://primefaces.org/ui"&gt;
  
      &lt;h:head&gt;&lt;/h:head&gt;
  
      &lt;h:form enctype="multipart/form-data"&gt;
          &lt;p:fileUpload fileUploadListener="#{fileUploadController.handleFileUpload}"
                        mode="advanced" 
                        update="messages"
                        sizeLimit="100000" 
                        allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/&gt;
  
          &lt;p:growl id="messages" showDetail="true"/&gt;
      &lt;/h:form&gt;
  
  &lt;/html&gt;
  
      &lt;/h:form&gt;
    &lt;/h:body&gt;
  </code></pre>
  
  <p>Here's the bean:</p>
  
  <pre><code>package fileUpload;
  
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.context.FacesContext;
  
  import org.primefaces.event.FileUploadEvent;
  
  @ManagedBean(name = "fileUploadController")
  public class fileUploadController {
  
      private String destination = "c:\test";
  
      public void upload(FileUploadEvent event) {
          FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");
          FacesContext.getCurrentInstance().addMessage(null, msg);
          // Do what you want with the file        
          try {
              copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
          } catch (IOException e) {
              e.printStackTrace();
          }
  
      }
  
      public void copyFile(String fileName, InputStream in) {
          try {
  
  
              // write the inputStream to a FileOutputStream
              OutputStream out = new FileOutputStream(new File(destination + fileName));
  
              int read = 0;
              byte[] bytes = new byte[1024];
  
              while ((read = in.read(bytes)) != -1) {
                  out.write(bytes, 0, read);
              }
  
              in.close();
              out.flush();
              out.close();
  
              System.out.println("New file created!");
          } catch (IOException e) {
              System.out.println(e.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>What have I missed out?</p>
  
  <pre><code>WARNING: PWC4011: Unable to set request character encoding to UTF-8 from context /FileUpload, because request parameters have already been read, or ServletRequest.getReader() has already been called
  WARNING: /index.xhtml @15,63 fileUploadListener="#{fileUploadController.handleFileUpload(event)}": Method handleFileUpload not found
  javax.el.MethodNotFoundException: /index.xhtml @15,63 fileUploadListener="#{fileUploadController.handleFileUpload(event)}": Method handleFileUpload not found
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
      at org.primefaces.component.fileupload.FileUpload.broadcast(FileUpload.java:279)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:759)
      at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:935)
      at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
      at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:77)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
      at java.lang.Thread.run(Thread.java:722).
  </code></pre>