13 Replies Latest reply on Dec 19, 2008 4:36 AM by hassounbs

    problem with rich:FileUpload

    milankoko

      I am having trouble with richfaces fileUpload component. When uploading should start it throws a null pointer exception and does nothing. I'm running richfaces on tomcat 6.0.16 alongside myfaces 1.2.3, tomahawk 1.1.6 and sandbox 1.1.7.

      This is the error I get:

      http-80-2 - ERROR [11 jun 2008 12:06:27,921] _ErrorPageWriter - An exception occurred
      javax.faces.FacesException: Exception while decoding component : {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /pages/retailers/placeAction.jsp][Class: javax.faces.component.html.HtmlForm,Id: inputForm][Class: javax.faces.component.html.HtmlPanelGrid,Id: j_id_jsp_1435835908_43][Class: org.richfaces.component.html.HtmlFileUpload,Id: upload]}
       at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:566)
       at javax.faces.component.UIInput.decode(UIInput.java:184)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:692)
       at javax.faces.component.UIInput.processDecodes(UIInput.java:114)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:688)
       at javax.faces.component.UIForm.processDecodes(UIForm.java:57)
       at org.ajax4jsf.component.AjaxViewRoot$1.invokeContextCallback(AjaxViewRoot.java:388)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:235)
       at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:405)
       at org.apache.myfaces.lifecycle.ApplyRequestValuesExecutor.execute(ApplyRequestValuesExecutor.java:32)
       at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:103)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:76)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:148)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:100)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:154)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:362)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
       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:147)
       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:175)
       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:844)
       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(Thread.java:619)
      Caused by: 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:562)
       ... 36 more


      My code in jsp:

      <rich:fileUpload
       uploadData="#{placeActionManager.files}"
       fileUploadListener="#{placeActionManager.imageUploadListener}"
       maxFilesQuantity="3" id="upload"
       acceptedTypes="jpg, gif, png, bmp"
       addControlLabel="#{msgs.addFileControlLabel}"
       clearAllControlLabel="#{msgs.clearAllFilesControlLabel}"
       clearControlLabel="#{msgs.clearFileControlLabel}"
       stopEntryControlLabel="#{msgs.stopFileEntryControlLabel}"
       uploadControlLabel="#{msgs.uploadFileControlLabel}">
       <a4j:support event="onuploadcomplete" reRender="info" />
      </rich:fileUpload>


      I guess there is some kind of problem rendering the component? pick list from richfaces works fine for me.

        • 1. Re: problem with rich:FileUpload
          ilya_shaikovsky

          the problems could be in your configuration.

          check please an example of config file.

          http://jira.jboss.com/jira/browse/RF-3096

          • 2. Re: problem with rich:FileUpload
            milankoko

            example you posted worked fine, but I still don't know what I'm doing wrong. I even tried putting your fileUpload on my page but it didn't work, same error. Configuration file web.xml looks fine to me:

            <?xml version="1.0" encoding="ISO-8859-2"?>
            
            <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
             version="2.4">
            
             <context-param>
             <param-name>org.richfaces.SKIN</param-name>
             <param-value>blueSky</param-value>
             </context-param>
            
             <context-param>
             <param-name>javax.faces.CONFIG_FILES</param-name>
             <param-value>/WEB-INF/faces-config.xml</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>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
             <param-value>true</param-value>
             </context-param>
            
             <context-param>
             <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
             <param-value>false</param-value>
             </context-param>
            
             <context-param>
             <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
             <param-value>true</param-value>
             </context-param>
            
             <context-param>
             <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
             <param-value>true</param-value>
             </context-param>
            
            <filter>
             <display-name>RichFaces Filter</display-name>
             <filter-name>richfaces</filter-name>
             <filter-class>org.ajax4jsf.Filter</filter-class>
             <init-param>
             <!-- max file size in bytes for upload -->
             <param-name>maxRequestSize</param-name>
             <param-value>500000</param-value>
             </init-param>
             <init-param>
             <param-name>createTempFiles</param-name>
             <param-value>true</param-value>
             </init-param>
             </filter>
            
             <!-- Extensions Filter for tomahawk and others-->
             <filter>
             <filter-name>MyFacesExtensionsFilter</filter-name>
             <filter-class>
             org.apache.myfaces.webapp.filter.ExtensionsFilter
             </filter-class>
             <init-param>
             <param-name>uploadMaxFileSize</param-name>
             <param-value>500k</param-value>
             </init-param>
             <init-param>
             <param-name>uploadThresholdSize</param-name>
             <param-value>500k</param-value>
             </init-param>
             </filter>
            
             <filter-mapping>
             <filter-name>richfaces</filter-name>
             <servlet-name>Faces Servlet</servlet-name>
             <dispatcher>REQUEST</dispatcher>
             <dispatcher>FORWARD</dispatcher>
             <dispatcher>INCLUDE</dispatcher>
             <dispatcher>ERROR</dispatcher>
             </filter-mapping>
            
             <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages -->
             <filter-mapping>
             <filter-name>MyFacesExtensionsFilter</filter-name>
             <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
             <servlet-name>Faces Servlet</servlet-name>
             </filter-mapping>
            
             <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
             <filter-mapping>
             <filter-name>MyFacesExtensionsFilter</filter-name>
             <url-pattern>/faces/*</url-pattern>
             </filter-mapping>
            
             <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) -->
             <filter-mapping>
             <filter-name>MyFacesExtensionsFilter</filter-name>
             <url-pattern>*.jsf</url-pattern>
             </filter-mapping>
            
             <!-- Listener, that does all the startup work (configuration, init). -->
             <listener>
             <listener-class>
             org.apache.myfaces.webapp.StartupServletContextListener
             </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>
            
             <servlet>
             <servlet-name>autocomplete</servlet-name>
             <servlet-class>
             net.brainsoft.va.server.servlets.AutocompleteServlet
             </servlet-class>
             <load-on-startup>2</load-on-startup>
             </servlet>
            
             <servlet-mapping>
             <servlet-name>autocomplete</servlet-name>
             <url-pattern>/autocomplete.view</url-pattern>
             </servlet-mapping>
            
             <welcome-file-list>
             <welcome-file>index.jsp</welcome-file>
             <welcome-file>index.html</welcome-file>
             </welcome-file-list>
            
            </web-app>
            


            Now I noticed a couple of differences in contrast to your example:
            - I don't use facelets
            - I don't have tomahawk.taglib.xml file, since I'm running on Tomcat 6 which doesn't need it i think
            - I use <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%> instead of xmlns.
            - your examle does not include tomahawk or sandbox or ajax4jsf namespace on page that has fileInput component on it

            Could any of this things cause my error? As I mentioned, rich:pickList works fine.

            • 3. Re: problem with rich:FileUpload
              milankoko

              i fixed that problem. I needed to place core-3.2.1.GA and laguna-3.2.1.GA in my lib folder. Weird because I don't remember I read anything about placing them in classpath in installation instructions. What do they contain? I presume laguna is skin.

              But my fileUpload still does not work. I get no errors which is not good since I don't have a clue of whats wrong. When upload of file automatically starts or I choose to start it, file upload listener is not called.

              Here is what log says:

              http-80-1 - WARN [12 jun 2008 00:20:16,343] UIComponentBase - WARNING: Component login:j_id27 just got an automatic id, because there was no id assigned yet. If this component was created dynamically (i.e. not by a JSP tag) you should assign it an explicit static id or assign it the id you get from the createUniqueId from the current UIViewRoot component right after creation! Path to Component: {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /pages/home.jsp][Class: javax.faces.component.html.HtmlForm,Id: login][Class: org.richfaces.component.html.HtmlFileUpload,Id: j_id_jsp_1452984900_8][Class: org.richfaces.component.html.HtmlProgressBar,Id: j_id27]}
              http-80-2 - DEBUG [12 jun 2008 00:20:16,375] FacesServlet - service end
              http-80-1 - DEBUG [12 jun 2008 00:20:16,437] FacesServlet - service end
              http-80-2 - DEBUG [12 jun 2008 00:20:17,078] FacesServlet - service begin
              http-80-2 - DEBUG [12 jun 2008 00:20:17,156] FacesServlet - service end
              http-80-2 - DEBUG [12 jun 2008 00:20:18,281] FacesServlet - service begin
              http-80-2 - DEBUG [12 jun 2008 00:20:18,421] FacesServlet - service end
              http-80-2 - DEBUG [12 jun 2008 00:20:19,593] FacesServlet - service begin
              http-80-2 - DEBUG [12 jun 2008 00:20:19,656] FacesServlet - service end
              ....
              


              What's wrong now?

              • 4. Re: problem with rich:FileUpload
                milankoko

                I did some more testing and found out that if I put latest libraries(3.2.1GA) in your example(which dates to 16.4.2008) your example no longer works. It does not report any error other than Transfer error occurred in fileUpload panel.

                • 5. Re: problem with rich:FileUpload
                  justadreamer2007

                  Same thing with me - I had a working (except for IE6) rich:fileUpload from richfaces-3.2.0.SR1, and then I updated to richfaces-3.2.1.GA. Now when you try to upload a file it says 'Transfer error occuried' (should say occurred). What's up with that? Something might have been spoiled between releases I guess.

                  • 6. Re: problem with rich:FileUpload
                    milankoko

                    I think there is some kind of conflict with latest version of richfaces. Snapshot from 18.4.2008 works fine, but if you switch to latest GA release it gives you transfer error. Funny thing, if you look into your temp files folder in tomcat, the file is actually transferred. Somebody should look into that problem.

                    • 7. Re: problem with rich:FileUpload
                      mail.micke

                      Just wanted to say it works fine for me.

                      Just implemented pretty much the same page which is in the livedemo and it works fine.

                      I'm using :
                      3.2.1.GA
                      Mojarra
                      Seam 2.0.1.GA
                      Facelets 1.1.14
                      Tomcat 5.5

                      In order to help other help you it would probably be useful if you posted some code and more information about your environment.

                      If you are using Seam have you disabled their multipart filter ?

                      Cheers,

                      • 8. Re: problem with rich:FileUpload
                        mail.micke

                        Sorry,
                        just spotted you environment information. Quite different from mine.

                        • 9. Re: problem with rich:FileUpload
                          justadreamer2007

                          Hi, mail.micke@gmail.com, thanx for reply because I am trying to resolve this issue too

                          My environment is:

                          SJSAS 9.1_ur_1 = glassfish 9.1_ur_1
                          Mojarra JSF 1.2_08
                          richfaces-3.2.1.GA

                          in web.xml I have:

                           <filter>
                           <display-name>RichFaces Filter</display-name>
                           <filter-name>richfaces</filter-name>
                           <filter-class>org.ajax4jsf.Filter</filter-class>
                           <init-param>
                           <param-name>createTempFiles</param-name>
                           <param-value>false</param-value>
                           </init-param>
                           <init-param>
                           <param-name>maxRequestSize</param-name>
                           <param-value>1000000</param-value>
                           </init-param>
                           </filter>
                           <filter-mapping>
                           <filter-name>richfaces</filter-name>
                           <servlet-name>Faces Servlet</servlet-name>
                           <dispatcher>REQUEST</dispatcher>
                           <dispatcher>FORWARD</dispatcher>
                           <dispatcher>INCLUDE</dispatcher>
                           </filter-mapping>
                          

                          creatTempFile=false means that I want to get my data in the listener in
                          uploadEvent.getUploadItem().getData()
                          , the thing is that I even get this data for the first uploaded file, but no onuploadcomplete event is fired - and it says Transfer error occurred.
                          This seems to be incorrect. createTempFile=true - has the same effect. I will make a simple webapp to demonstrate this behaviour and if the behaviour is the same as in my big app - I will place an issue to jira.

                          • 10. Re: problem with rich:FileUpload
                            milankoko

                            any hope of this issue being resolved soon? It's kind of disturbing for me to have to work on some snapshot and not having new releases available

                            • 11. Re: problem with rich:FileUpload

                               

                              "milankoko" wrote:
                              i fixed that problem. I needed to place core-3.2.1.GA and laguna-3.2.1.GA in my lib folder. Weird because I don't remember I read anything about placing them in classpath in installation instructions. What do they contain? I presume laguna is skin.

                              But my fileUpload still does not work. I get no errors which is not good since I don't have a clue of whats wrong. When upload of file automatically starts or I choose to start it, file upload listener is not called.

                              Here is what log says:

                              http-80-1 - WARN [12 jun 2008 00:20:16,343] UIComponentBase - WARNING: Component login:j_id27 just got an automatic id, because there was no id assigned yet. If this component was created dynamically (i.e. not by a JSP tag) you should assign it an explicit static id or assign it the id you get from the createUniqueId from the current UIViewRoot component right after creation! Path to Component: {Component-Path : [Class: org.ajax4jsf.component.AjaxViewRoot,ViewId: /pages/home.jsp][Class: javax.faces.component.html.HtmlForm,Id: login][Class: org.richfaces.component.html.HtmlFileUpload,Id: j_id_jsp_1452984900_8][Class: org.richfaces.component.html.HtmlProgressBar,Id: j_id27]}
                              http-80-2 - DEBUG [12 jun 2008 00:20:16,375] FacesServlet - service end
                              http-80-1 - DEBUG [12 jun 2008 00:20:16,437] FacesServlet - service end
                              http-80-2 - DEBUG [12 jun 2008 00:20:17,078] FacesServlet - service begin
                              http-80-2 - DEBUG [12 jun 2008 00:20:17,156] FacesServlet - service end
                              http-80-2 - DEBUG [12 jun 2008 00:20:18,281] FacesServlet - service begin
                              http-80-2 - DEBUG [12 jun 2008 00:20:18,421] FacesServlet - service end
                              http-80-2 - DEBUG [12 jun 2008 00:20:19,593] FacesServlet - service begin
                              http-80-2 - DEBUG [12 jun 2008 00:20:19,656] FacesServlet - service end
                              ....
                              


                              What's wrong now?



                              I found one difference from your web.xml and my example provided in JIRA. You should map myfaces extension filter on Faces Servlet, not on page extension *.jsf. I think this is cause of listener skipping after file uploaded in your application.

                              Please remove the following code from web.xml:


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



                              • 12. Re: problem with rich:FileUpload

                                 

                                "milankoko" wrote:
                                I think there is some kind of conflict with latest version of richfaces. Snapshot from 18.4.2008 works fine, but if you switch to latest GA release it gives you transfer error. Funny thing, if you look into your temp files folder in tomcat, the file is actually transferred. Somebody should look into that problem.


                                Can you please define if uploadListener was called after 'transfer error' message occurred?
                                Which browser do you use for test?

                                Thanks.

                                • 13. Re: problem with rich:FileUpload

                                  utilise le code :

                                  <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
                                   maxFilesQuantity="25" immediate="true"
                                   uploadData="#{fileUploadBean.files}"
                                   reRender="table" id="upload"
                                   acceptedTypes="jpg, gif, png, bmp">
                                   <f:facet name="progress" id="test">
                                   <rich:progressBar style="width: 100%;"/>
                                   </f:facet>
                                   </rich:fileUpload>