3 Replies Latest reply on Sep 10, 2009 3:59 AM by Ogi Prayogo

    rich:fileUpload getting NullPointerException, code similar w

    Ogi Prayogo Newbie

      Hi,

      Im trying the <rich:uploadFile> tag from Richfaces, and I ran into error, I was kinda hoping i could get some info from the forum.

      my code is as follows

      <body>
      <f:view>
       <h:form>
       <rich:fileUpload fileUploadListener="#{uploadBean.listener}"
       id="upload"
       acceptedTypes="jpg, gif, png, bmp" >
       </rich:fileUpload>
       </h:form>
      </f:view>
      </body>
      


      My uploadBean class has listener method, and it looks like the following:

      public void listener(UploadEvent event) throws Exception {
       log.debug("listener called");
       UploadItem item = event.getUploadItem();
       File file = new File();
       file.setLength(item.getData().length);
       file.setName(item.getFileName());
       file.setData(item.getData());
       log.debug(file.getName());
      }
      


      Basically, it looks almost identical with the RichFaces livedemo. However, I am getting the following error:

      [15:26:48][ERROR] BaseXMLFilter.doXmlFilter: 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:347)
       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.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:595)
      Caused by: java.lang.NullPointerException
       at com.sun.faces.mgbean.ManagedMapBeanBuilder.bake(ManagedMapBeanBuilder.java:73)
       at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:311)
       at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:201)
       at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
       at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
       at org.apache.el.parser.AstValue.getTarget(AstValue.java:63)
       at org.apache.el.parser.AstValue.invoke(AstValue.java:168)
       at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
       at org.richfaces.component.UIFileUpload.broadcast(UIFileUpload.java:190)
       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
       at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:294)
       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
       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)
       ... 18 more
      
      


      anybody can help me out where I did wrong? Thank you in advance :D

      My environment spec is:
      - tomcat 6.0.18
      - jdk 1.5
      - facelets


        • 1. Re: rich:fileUpload getting NullPointerException, code simil
          Ogi Prayogo Newbie

          changed the xhtml to the following


          <rich:fileUpload uploadData="#{uploadBean.file}"
           autoclear="true"
           maxFilesQuantity="1"
           fileUploadListener="#{uploadBean.listener}"
           id="upload"
           acceptedTypes="jpg, gif, png, bmp">
          </rich:fileUpload>
          


          Now, the error looks abit different

          
          [12:00:04][ERROR] BaseXMLFilter.doXmlFilter: 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:347)
           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.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:595)
          Caused by: java.lang.NullPointerException
           at com.sun.faces.mgbean.ManagedMapBeanBuilder.bake(ManagedMapBeanBuilder.java:73)
           at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:311)
           at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:201)
           at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
           at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
           at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
           at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
           at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
           at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
           at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
           at org.richfaces.renderkit.FileUploadRendererBase.storeData(FileUploadRendererBase.java:390)
           at org.richfaces.renderkit.FileUploadRendererBase.onUploadComplete(FileUploadRendererBase.java:408)
           at org.richfaces.renderkit.FileUploadRendererBase.doDecode(FileUploadRendererBase.java:161)
           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.UIForm.processDecodes(UIForm.java:209)
           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)
           ... 18 more
          
          


          pls help...

          • 2. Re: rich:fileUpload getting NullPointerException, code simil
            Nick Belaevski Master

            Looks like problem in beans configuration, please check managed maps for possible cause of NPE.

            • 3. Re: rich:fileUpload getting NullPointerException, code simil
              Ogi Prayogo Newbie

              thank you for pointing out the possible cause. I have found the error, and now it is working perfectly. much appreciated.