title: file upload java / jsf / primefaces
body: <p>I'm trying to upload a text document to my server and it drives my crazy for a couple of days. Basically the method which suppose to be fired #{bookController.handleFileUpload} when the file is uploaded does not fire, but I don't get any errors and on the front end the file looks like it is uploaded. I assume the file gets consumed somewhere on the way to my controller method.
  Here is my web.xml</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;/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;context-param&gt;
      &lt;param-name&gt;primefaces.THEME&lt;/param-name&gt;
      &lt;param-value&gt;south-street&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;servlet&gt;
      &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/jpmorgan/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;context-param&gt;
  </code></pre>
  
  <p>I added the necessary jars (common-io.jar &amp; common-fileupload.jar) to my pom.xml. 
  Here is my page that suppose to handle the file:</p>
  
  <pre><code>&lt;!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      template="/WEB-INF/layouts/no-ajax.xhtml"&gt;
  
      &lt;ui:define name="head"&gt;
  
      &lt;/ui:define&gt;
  
      &lt;ui:define name="title"&gt;#{msg['add_book']}&lt;/ui:define&gt;
  
      &lt;ui:define name="content"&gt;
          &lt;h:form id="form" enctype="multipart/form-data"&gt;
  
              &lt;p:messages id="messages" autoUpdate="true"/&gt;
              &lt;p:panelGrid id="grid"&gt;
  
              &lt;p:row&gt; &lt;p:column&gt;
                  &lt;h:outputLabel for="name" value="#{msg['label_book_title']}" /&gt;
                  &lt;p:spacer width="100" height="10" /&gt;
                  &lt;p:inputText id="name" value="#{bookBean.book.title}"/&gt;
              &lt;/p:column&gt; &lt;/p:row&gt;    
              &lt;p:row&gt; &lt;p:column&gt;
  
                 &lt;p:fileUpload id="upload" value="#{bookBean.file}"
                                dragDropSupport="true"
                                update="messages"
                                fileUploadListener="#{bookController.handleFileUpload}" /&gt;
  
              &lt;/p:column&gt; &lt;/p:row&gt;
              &lt;/p:panelGrid&gt;
  
              &lt;p:toolbar&gt;  
                  &lt;p:toolbarGroup align="left"&gt;
                      &lt;p:commandButton value="#{msg['button_next']}" action="next" execute="@form" update="@form"/&gt;
                      &lt;p:commandButton value="#{msg['button_cancel']}" action="exit" execute="@form" update="@form"/&gt;
                  &lt;/p:toolbarGroup&gt;
              &lt;/p:toolbar&gt;
  
          &lt;/h:form&gt;
      &lt;/ui:define&gt;
  
      &lt;ui:define name="help"&gt;
  
      &lt;h:outputText value="#{msg['help_add_page']}" /&gt; 
  
      &lt;/ui:define&gt;
  
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>And layout for the above page:</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"
      xmlns:sec="http://www.springframework.org/security/tags"
      xmlns:ui="http://java.sun.com/jsf/facelets"&gt;
  
  &lt;f:view contentType="text/html"&gt;
  
      &lt;h:head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
          &lt;title&gt;#{msg['application_name']}&lt;/title&gt;
  
          &lt;link rel="icon" href="resources/resources/images/favicon.ico" type="image/x-icon" /&gt;
          &lt;link rel="shortcut icon" href="resources/resources/images/favicon.ico" /&gt;
          &lt;link rel="stylesheet" href="resources/resources/styles/blueprint/screen.css" type="text/css" media="screen, projection" /&gt;
          &lt;link rel="stylesheet" href="resources/resources/styles/blueprint/print.css" type="text/css" media="print" /&gt;
          &lt;!--[if lt IE 8]&gt;
              &lt;link rel="stylesheet" href="${request.servletPath}/styles/blueprint/ie.css" type="text/css" media="screen, projection" /&gt;
          &lt;![endif]--&gt;
      &lt;/h:head&gt;
  
      &lt;h:body&gt;
          &lt;p:layout fullPage="true"&gt;
  
              &lt;p:layoutUnit id="top" position="north" header="#{msg['application_name']}" size="100" collapsible="true" collapsed="false" resizable="true"&gt;
                  &lt;ui:insert name="title" /&gt;
              &lt;/p:layoutUnit&gt;
  
              &lt;p:layoutUnit id="west" position="west" size="250" header="#{msg['label_help']}" resizable="true" collapsible="true" collapsed="false"&gt;
                  &lt;ui:insert name="help" /&gt;
              &lt;/p:layoutUnit&gt;
  
              &lt;p:layoutUnit id="center" position="center" &gt;
                  &lt;ui:insert name="content" /&gt;
              &lt;/p:layoutUnit&gt;
  
          &lt;/p:layout&gt;
  
      &lt;/h:body&gt;
  
  &lt;/f:view&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Does anyone have an idea what I do wrong?
  Big Thanks.</p>