12 Replies Latest reply on Nov 17, 2009 9:27 AM by zorgblub

    Problem with fileupload class org.richfaces.event.UploadAjax

    goompas

      Hi
      I have problem with rich:fileupload component.
      My xhtml look like that

      <h:panelGrid columns="2" columnClasses="top,top">
       <rich:fileUpload fileUploadListener="#{FilesUploadMB.listener}"
       maxFilesQuantity="#{FilesUploadMB.uploadsAvailable}"
       id="upload"
       immediateUpload="#{FilesUploadMB.autoUpload}"
       acceptedTypes="jpg, gif, png, bmp" allowFlash="#{FilesUploadMB.useFlash}">
       <a4j:support event="onuploadcomplete" reRender="fileinfo" />
       </rich:fileUpload>
      
       </h:panelGrid>


      Action
      public void listener(UploadEvent event) throws Exception
       {
       System.out.println("listener ");
       UploadItem item = event.getUploadItem();
      
       File file = new File();
       file.setLength(item.getData().length);
       file.setName(item.getFileName());
       file.setData(item.getData());
       System.out.println("file size "+file.getLength());
       files.add(file);
       uploadsAvailable--;
       }


      Now, when i click upload file i have error
      An Error Occurred:
      FacesEvent of class org.richfaces.event.UploadAjaxActionEvent not supported by UIInput


      Why org.richfaces.event.UploadAjaxActionEvent. I dont use it. I use
      import org.richfaces.event.UploadEvent;


        • 1. Re: Problem with fileupload class org.richfaces.event.Upload
          nbelaevski

          Are you using MyFaces? Try the latest one.

          • 2. Re: Problem with fileupload class org.richfaces.event.Upload
            goompas

            Yes, we using latest MyFaces 1.2.3

            • 3. Re: Problem with fileupload class org.richfaces.event.Upload
              goompas

              Sorry for duble post, but there is no edit
              i add stact trace

              java.lang.IllegalArgumentException: FacesEvent of class org.richfaces.event.UploadAjaxActionEvent not supported by UIInput
               at javax.faces.component.UIInput.broadcast(UIInput.java:192)
               at org.richfaces.component.UIFileUpload.broadcast(UIFileUpload.java:221)
               at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
               at org.ajax4jsf.component.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:340)
               at org.ajax4jsf.application.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:216)
               at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:169)
               at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
               at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
               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:368)
               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 mikronika.se.env.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:58)
               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: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(Thread.java:619)
              


              • 4. Re: Problem with fileupload class org.richfaces.event.Upload
                nbelaevski

                 

                "goompas" wrote:
                Yes, we using latest MyFaces 1.2.3

                That's not the latest one.

                • 5. Re: Problem with fileupload class org.richfaces.event.Upload
                  goompas

                  You have right. Now i have MyFaces 12.7 and there is no exc, but fileUploadListener is not called. I have enctype "multipart/form-data".

                  • 6. Re: Problem with fileupload class org.richfaces.event.Upload
                    nbelaevski

                    Make sure you have configured filters properly. Take a look at documentation for more info.

                    • 7. Re: Problem with fileupload class org.richfaces.event.Upload
                      zorgblub

                      I have exactly the same problem with MyFaces 1.2.7 and RichFaces 3.3.2 SR1.

                      It seems that it has been a problem a while ago : http://jira.jboss.com/jira/browse/RF-2514 . But this should have been fixed on 3.2.1 so I don't understand why is it still a problem.

                      • 8. Re: Problem with fileupload class org.richfaces.event.Upload
                        ilya_shaikovsky

                         


                        Make sure you have configured filters properly. Take a look at documentation for more info.

                        the same question for you..

                        • 9. Re: Problem with fileupload class org.richfaces.event.Upload
                          zorgblub

                          I followed the documentation instructions about the filters and still no changes. I'm using the example from LiveDemo so it's probably not a code-related problem.

                          Here is my web.xml :

                          <?xml version="1.0" encoding="UTF-8"?>
                          <web-app version="2.4"
                           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">
                          
                           <!-- Facelets Configuration -->
                           <context-param>
                           <param-name>facelets.DEVELOPMENT</param-name>
                           <param-value>true</param-value>
                           </context-param>
                           <context-param>
                           <!-- Refresh the pages so we can edit pages while running the application -->
                           <param-name>facelets.REFRESH_PERIOD</param-name>
                           <param-value>2</param-value>
                           </context-param>
                           <context-param>
                           <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                           <param-value>.xhtml</param-value>
                           </context-param>
                           <context-param>
                           <param-name>facelets.VIEW_MAPPINGS</param-name>
                           <param-value>*.xhtml</param-value>
                           </context-param>
                           <context-param>
                           <description>see bug https://issues.apache.org/jira/browse/MYFACES-1786
                           ...if the web container is restarted, a new secret is generated..causing javax.crypto.BadPaddingException
                           when JSF tries to restore state
                           </description>
                           <param-name>org.apache.myfaces.USE_ENCRYPTION</param-name>
                           <param-value>false</param-value>
                           </context-param>
                           <context-param>
                           <param-name>facelets.SKIP_COMMENTS</param-name>
                           <param-value>true</param-value>
                           </context-param>
                          
                           <!-- MyFaces Configuration -->
                           <context-param>
                           <!-- Disables state compression on server -->
                           <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
                           <param-value>false</param-value>
                           </context-param>
                           <context-param>
                           <!-- Disables state serialization on server -->
                           <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
                           <param-value>false</param-value>
                           </context-param>
                           <context-param>
                           <param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
                           <param-value>false</param-value>
                           </context-param>
                          
                           <!-- RichFaces Configuration -->
                           <context-param>
                           <param-name>org.richfaces.SKIN</param-name>
                           <param-value>blueSky</param-value>
                           </context-param>
                           <context-param>
                           <param-name>org.ajax4jsf.handleViewExpiredOnClient</param-name>
                           <param-value>true</param-value>
                           </context-param>
                           <context-param>
                           <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
                           <param-value>com.sun.facelets.FaceletViewHandler</param-value>
                           </context-param>
                          
                           <!-- Ajax4jsf Filter -->
                           <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>true</param-value>
                           </init-param>
                           <init-param>
                           <param-name>maxRequestSize</param-name>
                           <param-value>20000000</param-value>
                           </init-param>
                           </filter>
                           <!-- MyFaces ExtensionsFilter -->
                           <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>ajax4jsf</filter-name>
                           <servlet-name>Faces Servlet</servlet-name>
                           <dispatcher>REQUEST</dispatcher>
                           <dispatcher>FORWARD</dispatcher>
                           <dispatcher>INCLUDE</dispatcher>
                           <dispatcher>ERROR</dispatcher>
                           </filter-mapping>
                           <filter-mapping>
                           <filter-name>extensionsFilter</filter-name>
                           <servlet-name>Faces Servlet</servlet-name>
                           </filter-mapping>
                          
                          
                           <session-config>
                           <!-- A longer session allows the RichFaces JS to run more smoothly. -->
                           <session-timeout>1200</session-timeout>
                           </session-config>
                          
                           <!-- Spring Context loader -->
                           <listener>
                           <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                           </listener>
                           <listener>
                           <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
                           </listener>
                           <context-param>
                           <param-name>contextConfigLocation</param-name>
                           <param-value>
                           classpath*:eu/europarl/epped/hr/config/spring-all.xml
                           </param-value>
                           </context-param>
                          
                           <!-- Spring-security -->
                           <filter>
                           <filter-name>springSecurityFilterChain</filter-name>
                           <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
                           </filter>
                           <filter-mapping>
                           <filter-name>springSecurityFilterChain</filter-name>
                           <url-pattern>/*</url-pattern>
                           <dispatcher>FORWARD</dispatcher>
                           <dispatcher>REQUEST</dispatcher>
                           </filter-mapping>
                          
                           <!-- Spring/Hibernate OpenSession Filter -->
                           <filter>
                           <filter-name>hibernateFilter</filter-name>
                           <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
                           </filter>
                          
                           <filter-mapping>
                           <filter-name>hibernateFilter</filter-name>
                           <servlet-name>Faces Servlet</servlet-name>
                           </filter-mapping>
                          
                           <!-- JSF Servlet -->
                           <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>
                          
                           <!-- Makes sure that the pages are never accessed directly
                           without going through the *.faces pattern. -->
                           <security-constraint>
                           <display-name>Restrict access to raw pages</display-name>
                           <web-resource-collection>
                           <web-resource-name>Restrict access to raw pages</web-resource-name>
                           <url-pattern>*.xhtml</url-pattern>
                           </web-resource-collection>
                           <auth-constraint>
                           <description>With no roles defined, no access granted</description>
                           </auth-constraint>
                           </security-constraint>
                          
                           <error-page>
                           <exception-type>javax.faces.application.ViewExpiredException</exception-type>
                           <location>/index.html</location>
                           </error-page>
                           <error-page>
                           <exception-type>javax.faces.FacesException</exception-type>
                           <location>/index.html</location>
                           </error-page>
                          
                          </web-app>


                          Thanks you for such a fast reply !

                          • 10. Re: Problem with fileupload class org.richfaces.event.Upload
                            ilya_shaikovsky

                            modify Spring security filter definition to use Faces Servlet by name mapping. Now it's caaled before RF filter and that could cause problems.

                            • 11. Re: Problem with fileupload class org.richfaces.event.Upload
                              zorgblub

                              Doing that prevents me to login in my application with a 404 error on the login processing url. But even when I remove the spring security filter mapping, I get the error.

                              exception
                              
                              javax.servlet.ServletException: FacesEvent of class org.richfaces.event.UploadAjaxActionEvent not supported by UIInput
                               javax.faces.webapp._ErrorPageWriter.throwException(_ErrorPageWriter.java:401)
                               javax.faces.webapp.FacesServlet.handleLifecycleException(FacesServlet.java:221)
                               javax.faces.webapp.FacesServlet.service(FacesServlet.java:156)
                               org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
                               org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
                               org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
                               org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                               org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                               org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                               org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                               org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                              
                              root cause
                              
                              java.lang.IllegalArgumentException: FacesEvent of class org.richfaces.event.UploadAjaxActionEvent not supported by UIInput
                               javax.faces.component.UIInput.broadcast(UIInput.java:192)
                               org.richfaces.component.UIFileUpload.broadcast(UIFileUpload.java:221)
                               org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:318)
                               org.ajax4jsf.component.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:337)
                               org.ajax4jsf.application.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:216)
                               org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:169)
                               org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
                               org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
                               javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
                               org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
                               org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
                               org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
                               org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                               org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                               org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                               org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                               org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                              


                              • 12. Re: Problem with fileupload class org.richfaces.event.Upload
                                zorgblub

                                And actually, the upload is working perfectly because when a debug a can see the file I'm uploading in the listener method.

                                It's just that exception that is thrown...