4 Replies Latest reply on May 29, 2009 7:53 AM by Guilhermo Piva

    FileUpload issue

    Guilhermo Piva Newbie

      i have this fileUpload

      <rich:fileUpload acceptedTypes="jpg, gif, png, bmp" autoclear="true" fileUploadListener="#{MyBean.fileUpload}"/>


      this fileUploadListener
      private void fileUpload(UploadEvent e){
       System.out.println("Uploading something ");
      
       }


      and thats my web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
       <display-name>educaWebPortal</display-name>
       <filter>
       <display-name>Ajax4jsf Filter</display-name>
       <filter-name>ajax4jsf</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
       <init-param>
       <param-name>createTempFiles</param-name>
       <param-value>false</param-value>
       </init-param>
       </filter>
       <context-param>
       <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
       <param-value>.xhtml</param-value>
       </context-param>
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.REFRESH_PERIOD</param-name>
       <param-value>-1</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.DEVELOPMENT</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.validateXml</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.verifyObjects</param-name>
       <param-value>false</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>blueSky</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.CONTROL_SKINNING</param-name>
       <param-value>enable</param-value>
       </context-param>
       <context-param>
       <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
       <param-value>com.sun.facelets.FaceletViewHandler</param-value>
       </context-param>
       <filter-mapping>
       <filter-name>ajax4jsf</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>
       <filter>
       <filter-name>extensionsFilter</filter-name>
       <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
       <init-param>
       <description>
       Set the size limit for uploaded files. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
       </description>
       <param-name>uploadMaxFileSize</param-name>
       <param-value>100m</param-value>
       </init-param>
       <init-param>
       <description>
       Set the threshold size - files below this limit are stored in memory, files above this limit are stored on disk. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
       </description>
       <param-name>uploadThresholdSize</param-name>
       <param-value>100k</param-value>
       </init-param>
      </filter>
       <filter-mapping>
       <filter-name>extensionsFilter</filter-name>
       <url-pattern>*.jsf</url-pattern>
       </filter-mapping>
       <filter-mapping>
       <filter-name>extensionsFilter</filter-name>
       <url-pattern>*.faces</url-pattern>
       </filter-mapping>
       <filter-mapping>
       <filter-name>extensionsFilter</filter-name>
       <url-pattern>/faces/*</url-pattern>
       </filter-mapping>
       <listener>
       <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
       </listener>
       <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/applicationContext.xml</param-value>
       </context-param>
       <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
       <servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.jsf</url-pattern>
       </servlet-mapping>
       <welcome-file-list>
       <welcome-file>index.html</welcome-file>
       </welcome-file-list>
      </web-app>



      when a click on upload button, that's what happens
      SEVERE: JSF1054: (Phase ID: APPLY_REQUEST_VALUES 2, View ID: /modulo/alunos/index.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@14a86b]
      28/05/2009 15:01:11 org.ajax4jsf.webapp.BaseXMLFilter doXmlFilter
      SEVERE: Exception in the filter chain
      javax.servlet.ServletException
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:365)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:301)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Unknown Source)
      Caused by: java.lang.NullPointerException
       at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:140)
       at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
       at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:789)
       at javax.faces.component.UIInput.decode(UIInput.java:725)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1031)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at org.richfaces.component.UISwitchablePanel.processDecodes(UISwitchablePanel.java:170)
       at org.richfaces.component.UITabPanel.processDecodes(UITabPanel.java:155)
       at org.ajax4jsf.component.UIAjaxForm.processDecodes(UIAjaxForm.java:63)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:392)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
       at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:409)
       at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       ... 21 more
      28/05/2009 15:01:11 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:140)
       at org.ajax4jsf.renderkit.RendererBase.decode(RendererBase.java:75)
       at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:789)
       at javax.faces.component.UIInput.decode(UIInput.java:725)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1031)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at org.richfaces.component.UISwitchablePanel.processDecodes(UISwitchablePanel.java:170)
       at org.richfaces.component.UITabPanel.processDecodes(UITabPanel.java:155)
       at org.ajax4jsf.component.UIAjaxForm.processDecodes(UIAjaxForm.java:63)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:639)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1026)
       at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:392)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
       at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:409)
       at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:365)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:301)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Unknown Source)


      whats wrong ?

      ps: sorry for that long post ...

        • 1. Re: FileUpload issue
          Nick Belaevski Master

          Hi,

          RF filter should handle request before MyFaces extensions filter, however it is configured to work after it. Here is what Servlet spec. says:

          1. First, the <url-pattern> matching filter mappings in the same order that these
          elements appear in the deployment descriptor.
          2. Next, the <servlet-name> matching filter mappings in the same order that
          these elements appear in the deployment descriptor.

          • 2. Re: FileUpload issue
            Guilhermo Piva Newbie

            srry, but what exactly filters are we talking about ?

            • 3. Re: FileUpload issue
              Nick Belaevski Master

               

              <filter-mapping>
               <filter-name>ajax4jsf</filter-name>
               <servlet-name>Faces Servlet</servlet-name>
               <dispatcher>REQUEST</dispatcher>
               <dispatcher>FORWARD</dispatcher>
               <dispatcher>INCLUDE</dispatcher>
               </filter-mapping>
               <filter>
               <filter-name>extensionsFilter</filter-name>
               <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
               <init-param>
               <description>
               Set the size limit for uploaded files. Format: 10 - 10 bytes 10k - 10
              KB 10m - 10 MB 1g - 1 GB
               </description>
               <param-name>uploadMaxFileSize</param-name>
               <param-value>100m</param-value>
               </init-param>
               <init-param>
               <description>
               Set the threshold size - files below this limit are stored in memory,
              files above this limit are stored on disk. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB
               </description>
               <param-name>uploadThresholdSize</param-name>
               <param-value>100k</param-value>
               </init-param>
              </filter>
               <filter-mapping>
               <filter-name>extensionsFilter</filter-name>
               <url-pattern>*.jsf</url-pattern>
               </filter-mapping>
               <filter-mapping>
               <filter-name>extensionsFilter</filter-name>
               <url-pattern>*.faces</url-pattern>
               </filter-mapping>
               <filter-mapping>
               <filter-name>extensionsFilter</filter-name>
               <url-pattern>/faces/*</url-pattern>
               </filter-mapping>


              • 4. Re: FileUpload issue
                Guilhermo Piva Newbie

                so, i think i fixed it, partially, i delete those extensions filters

                 <filter-mapping>
                 <filter-name>extensionsFilter</filter-name>
                 <url-pattern>*.jsf</url-pattern>
                 </filter-mapping>
                 <filter-mapping>
                 <filter-name>extensionsFilter</filter-name>
                 <url-pattern>*.faces</url-pattern>
                 </filter-mapping>
                 <filter-mapping>
                 <filter-name>extensionsFilter</filter-name>
                 <url-pattern>/faces/*</url-pattern>
                 </filter-mapping>

                from my web.xml, and i got ir running ..

                but now, when a i click on upload button, it just doesn't access my method..
                i put some fileUploadListener, and declared the method like ir should be,:
                public void myMethod(UploadEvent e){
                }
                

                it is just not accessed, even if i provoke an exception, like a method that just not exists, it runs anyway.

                im using eclipse ganymede
                Eclipse Platform

                Version: 3.4.1

                i dont know if there is anything related to eclipse ide, or maybe it's just me ...