3 Replies Latest reply on Jul 30, 2008 4:53 AM by Andrei Markavtsov

    NullPointerException with fileUpload

    David Greenberg Newbie

      Hi,

      I can get a fileUpload component to display on my page, and all the functionality works until I press "Upload." At that point, I am getting the following error, and am guessing that I am simply overlooking something. Any help is greatly appreciated.

      Error:


      SEVERE: JSF1054: (Phase ID: APPLY_REQUEST_VALUES 2, View ID: /test.jsp) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@199c55a]
      Jul 29, 2008 12:50:53 PM org.apache.catalina.core.StandardWrapperValve invoke
      SEVERE: Servlet.service() for servlet Faces Servlet threw exception
      java.lang.NullPointerException
      at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:108)
      at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:76)
      at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:778)
      ...


      The contents of test.jsp are as follows:
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
       pageEncoding="ISO-8859-1"%>
      
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      
      <html>
       <f:view>
       <body>
       <div id="ltx-error">
       <h:messages />
       </div>
       <rich:fileUpload />
       </body>
       </f:view>
      </html>
      


      This is with JSF RI 1.2_07, Tomcat 6.0.16, RichFaces 3.2.1.GA. Any ideas?

      Thanks,
      David

        • 1. Re: NullPointerException with fileUpload
          David Greenberg Newbie

          I have also tried

          <h:form>
           <rich:fileUpload />
          </h:form>
          


          This gives the same error.

          • 2. Re: NullPointerException with fileUpload
            David Greenberg Newbie

            Figured it out. This is not strictly a RichFaces issue. I had Apache MyFaces ExtensionFilter configured in web.xml in order to use Tomahawk components. All multipart/form-data requests that are passed through ExtensionFilter get converted into a MultipartRequestWrapper, which always returns "application/x-www-form-urlencoded" as the contentType. The Ajax4Jsf BaseFilter does not recognize this as a multipart form request and, therefore, does not set the necessary session variable to parse the file upload. Since the FileUploadRendererBase requires this variable, a NullPointerException is thrown.

            Also, I had to get rid of Trinidad, which I wasn't using anyway.

            There is hope! Putting the ExtensionsFilter declaration (and mappings) after the RichFaces Filter declaration/mappings in web.xml seems to solve the issue.

            Thanks to anyone who looked into this.

            • 3. Re: NullPointerException with fileUpload
              Andrei Markavtsov Apprentice

              Hello. This is known issue.
              You should to configure AJAX & Extension filter to be sure that AJAX filter is processing firstly.

              Please look at the following issue: https://jira.jboss.org/jira/browse/RF-3096.
              There example attached with correctly configured filters. It works fine with myfaces.
              Look at those web.xml and keep the same filter declaration ordering and mapping.