6 Replies Latest reply on Sep 25, 2015 1:42 PM by aizoc chien

    rich:fileupload add button cannot be disabled on filesubmit event

    aizoc chien Newbie

      I use the rich:fileUpload component. When the file is submit, rendering "upload" causes null exception.

       

       

      I use listener="#{my.filesubmitListener}" to set flag #{my.filesubmitted} as true, and use render="upload" to invoke disabled="#{my.filesubmitted}".

      Is there any way to disable/greyout fileupload/add button UI on filesubmit event?

       

      <rich:fileUpload id="upload" disabled="#{my.filesubmitted}" autoclear="true" addLabel="fileupload" immediateUpload="true" fileUploadListener="#{my.fileListener}">

          <a4j:ajax event="filesubmit" listener="#{my.filesubmitListener}" render="upload"/>

          <a4j:ajax event="uploadcomplete" listener="#{my.uploadcompleteListener}" render="upload, info"/>

      </rich:fileUpload>


      <rich:panel id="info" ...>

      </rich:panel>

       

       

      Exception parsing multipart request: Request data cannot be read: org.richfaces.exception.FileUploadException: Exception parsing multipart request: Request data cannot be read
        at org.richfaces.request.MultipartRequestParser.parse(MultipartRequestParser.java:156) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]
        at org.richfaces.request.MultipartRequest25.parseIfNecessary(MultipartRequest25.java:77) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]
        at org.richfaces.request.MultipartRequest25.getParameter(MultipartRequest25.java:114) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]
        at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:91) [jsf-impl-2.1.28.jar:2.1.28]
        at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:62) [jsf-impl-2.1.28.jar:2.1.28]
        at java.util.Collections$UnmodifiableMap.get(Collections.java:1280) [classes.jar:1.6.0_65]
        at com.sun.faces.application.view.MultiViewHandler.calculateRenderKitId(MultiViewHandler.java:242) [jsf-impl-2.1.28.jar:2.1.28]
        at javax.faces.application.ViewHandlerWrapper.calculateRenderKitId(ViewHandlerWrapper.java:153) [jsf-api-2.1.28.jar:2.1]
        at com.sun.faces.context.FacesContextImpl.isPostback(FacesContextImpl.java:210) [jsf-impl-2.1.28.jar:2.1.28]
        at javax.faces.context.FacesContextWrapper.isPostback(FacesContextWrapper.java:402) [jsf-api-2.1.28.jar:2.1]
        at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:188) [jsf-impl-2.1.28.jar:2.1.28]
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.28.jar:2.1.28]
        at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.28.jar:2.1.28]
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.28.jar:2.1.28]
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jsf-api-2.1.28.jar:2.1]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
        at java.lang.Thread.run(Thread.java:695) [classes.jar:1.6.0_65]
      
      
      
      
      
      
        • 1. Re: rich:fileupload add button cannot be disabled on filesubmit event
          Michal Petrov Master

          That looks more like a problem with processing the uploaded file, is the fileUpload working without the listeners?

          • 2. Re: rich:fileupload add button cannot be disabled on filesubmit event
            aizoc chien Newbie

            Thank you for your quick reply.

            I tried to remove the render="upload" part from filesubmit event, the file listener is working without causing exception.

             

            <rich:fileUpload id="upload" disabled="#{my.filesubmitted}" autoclear="true" addLabel="fileupload" immediateUpload="true" fileUploadListener="#{my.fileListener}">

                <a4j:ajax event="filesubmit" listener="#{my.filesubmitListener}" render="upload"/>

                <a4j:ajax event="uploadcomplete" listener="#{my.uploadcompleteListener}" render="upload, info"/>

            </rich:fileUpload>

            <rich:panel id="info" ...>

            </rich:panel>

             

            However, with the setting render="upload" removed, the add button cannot be disabled immediately when file submitted. If add button is available for uploading more file, it causes the same problem.

            such as:

            1. upload a large file

            2. upload the second file when first file is still uploading

            => get the same error with below stack

             

            14:26:18,636 SEVERE [org.richfaces.log.Application] (http--127.0.0.1-8080-2) Exception parsing multipart request: Request data cannot be read: org.richfaces.exception.FileUploadException: Exception parsing multipart request: Request data cannot be read

              at org.richfaces.request.MultipartRequestParser.parse(MultipartRequestParser.java:156) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]

              at org.richfaces.request.MultipartRequest25.parseIfNecessary(MultipartRequest25.java:77) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]

              at org.richfaces.request.MultipartRequest25.getParameter(MultipartRequest25.java:114) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]

              at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:91) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:62) [jsf-impl-2.1.28.jar:2.1.28]

              at java.util.Collections$UnmodifiableMap.get(Collections.java:1280) [classes.jar:1.6.0_65]

              at com.sun.faces.application.view.MultiViewHandler.calculateRenderKitId(MultiViewHandler.java:242) [jsf-impl-2.1.28.jar:2.1.28]

              at javax.faces.application.ViewHandlerWrapper.calculateRenderKitId(ViewHandlerWrapper.java:153) [jsf-api-2.1.28.jar:2.1]

              at com.sun.faces.context.FacesContextImpl.isPostback(FacesContextImpl.java:210) [jsf-impl-2.1.28.jar:2.1.28]

              at javax.faces.context.FacesContextWrapper.isPostback(FacesContextWrapper.java:402) [jsf-api-2.1.28.jar:2.1]

              at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:188) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.28.jar:2.1.28]

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jsf-api-2.1.28.jar:2.1]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

              at java.lang.Thread.run(Thread.java:695) [classes.jar:1.6.0_65]

            Caused by: java.io.IOException: Request data cannot be read

              at org.richfaces.request.MultipartRequestParser.readData(MultipartRequestParser.java:279) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]

              at org.richfaces.request.MultipartRequestParser.readNext(MultipartRequestParser.java:294) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]

              at org.richfaces.request.MultipartRequestParser.parse(MultipartRequestParser.java:151) [richfaces-components-ui-4.3.7.Final.jar:4.3.7.Final]

              ... 28 more

             

            14:26:18,653 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[Faces Servlet]] (http--127.0.0.1-8080-2) Servlet.service() for servlet Faces Servlet threw exception: java.lang.NullPointerException

              at com.sun.faces.context.PartialViewContextImpl.createPartialResponseWriter(PartialViewContextImpl.java:469) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.context.PartialViewContextImpl.access$300(PartialViewContextImpl.java:76) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.context.PartialViewContextImpl$DelayedInitPartialResponseWriter.getWrapped(PartialViewContextImpl.java:603) [jsf-impl-2.1.28.jar:2.1.28]

              at javax.faces.context.PartialResponseWriter.startDocument(PartialResponseWriter.java:115) [jsf-api-2.1.28.jar:2.1]

              at org.richfaces.context.PartialResponseWriterWrapper.startDocument(PartialResponseWriterWrapper.java:32) [richfaces-core-impl-4.3.7.Final.jar:4.3.7.Final]

              at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:201) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:126) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.28.jar:2.1.28]

              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.28.jar:2.1.28]

              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jsf-api-2.1.28.jar:2.1]

              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]

              at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]

              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]

              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]

              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]

              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]

              at java.lang.Thread.run(Thread.java:695) [classes.jar:1.6.0_65]

            • 3. Re: rich:fileupload add button cannot be disabled on filesubmit event
              Michal Petrov Master

              If you're rerendering the fileUpload while the file is still being uploaded that's obviously going to break things. What are you trying to do?

              • 4. Re: rich:fileupload add button cannot be disabled on filesubmit event
                aizoc chien Newbie

                Hi Michal P.

                 

                Thanks for taking care of this problem. I would like to avoid the exception (break), but I still cannot find a better way to do so.

                 

                If not to render fileUpload component => user can use "add" button to upload a second file when first file being uploading. It cause the exception.

                 

                If render fileUpload component to disable "add" button => It's good that user is unable to use "add" button to upload another file when the a file uploading is in progress. But, as you said, rendering the fileUpload component when the file is still being uploaded breaks things.

                 

                Do you have any suggestion to avoid the exception?

                • 5. Re: rich:fileupload add button cannot be disabled on filesubmit event
                  Michal Petrov Master

                  You can just disable it on client side

                   

                  <h:outputScript>
                      disableUpload = function(event) {
                          RichFaces.component(event.target.id).maxFilesQuantity = -1;
                      }
                  </h:outputScript>
                  
                  <rich:fileUpload onfileselect="disableUpload(event)" … >
                  
                  • 6. Re: rich:fileupload add button cannot be disabled on filesubmit event
                    aizoc chien Newbie

                    Hi Michal P,

                     

                    Modifying on client side is an good option to avoid this problem!

                    I made changes yesterday and it works now. Thank you!

                     

                    function disableUploadKey() {

                      $(document).ready(function(){

                      $('input.rf-fu-inp').remove();

                      $('span.rf-fu-btn-cnt-add').toggleClass("rf-fu-btn-cnt-add-dis");

                      });

                    }