11 Replies Latest reply on Jun 3, 2008 2:03 PM by Victor Bucutea

    fileupload seems to have issuse  with item.getFileName()   -

    Phil Wilson Apprentice

      Hey Guys,

      I copied the demo code and I am getting an issue with null filename.

      I tried this on IE and FF...

      I have 3.2.0 GA and JSF 1.2

      ==================================

      import java.io.BufferedReader;
      import java.io.FileInputStream;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.io.OutputStream;
      import java.util.ArrayList;

      import java.io.File;


      import org.richfaces.event.UploadEvent;
      import org.richfaces.model.UploadItem;


      public class FileUploadBean{

      // I renamed the File class to RichFile

      private ArrayList files = new ArrayList();
      private int uploadsAvailable = 5;
      private boolean autoUpload = false;
      public int getSize() {
      if (getFiles().size()>0){
      return getFiles().size();
      }else
      {
      return 0;
      }
      }

      public FileUploadBean() {
      }

      public void paint(OutputStream stream, Object object) throws IOException {
      stream.write(getFiles().get((Integer)object).getData());
      }
      public void listener(UploadEvent event) throws Exception{

      UploadItem item = event.getUploadItem();

      System.out.println(" " );
      System.out.println("item.getFileName() 11 --->> " + item.getFileName());
      System.out.println(" " );

      RichFile file = new RichFile();
      file.setLength(item.getData().length);
      file.setName(item.getFileName());
      file.setData(item.getData());
      files.add(file);
      uploadsAvailable--;

      String out_file_name = "c:\\testPhil_121.jpg";

      System.out.println(" " );
      System.out.println("out_file_name --->> " + out_file_name);
      System.out.println(" " );

      System.out.println(" " );
      System.out.println("item.getFileName() --->> " + item.getFileName());
      System.out.println(" " );

      copyUploadedFile(item.getFileName(),out_file_name );
      }



      ===========================================================

      ARNING: org.apache.jasper.el.JspELException: /testAppFragments/profileMemberCongrats.jspf(61,12) '#{fileUploadBean.listener}' java.lang.NullPointerException
      javax.faces.el.EvaluationException: org.apache.jasper.el.JspELException: /testAppFragments/profileMemberCongrats.jspf(61,12) '#{fileUploadBean.listener}' java.lang.NullPointerException
      at org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor.invoke(MethodBindingMethodExpressionAdaptor.java:56)
      at org.richfaces.component.UIFileUpload.broadcast(UIFileUpload.java:160)
      at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:316)
      at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:289)
      at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:248)
      at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:404)
      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.BaseFilter.doFilter(BaseFilter.java:302)
      at org.ajax4jsf.Filter.doFilter(Filter.java:142)
      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:147)
      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
      at org.ajax4jsf.Filter.doFilter(Filter.java:142)
      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(Unknown Source)
      Caused by: org.apache.jasper.el.JspELException: /testAppFragments/profileMemberCongrats.jspf(61,12) '#{fileUploadBean.listener}' java.lang.NullPointerException
      at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:77)
      at org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor.invoke(MethodBindingMethodExpressionAdaptor.java:52)
      ... 30 more
      Caused by: java.lang.NullPointerException
      at com.testAppup.java.util.FileUploadBean.listener(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.apache.el.parser.AstValue.invoke(AstValue.java:152)
      at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
      ... 31 more

        • 1. Re: fileupload seems to have issuse  with item.getFileName()
          Phil Wilson Apprentice

          This is my code from jsp too.
          Also, I am using

          C:/Documents and Settings/Phil/.maven/repository/jsf/mojarra-1.2_08-b06-FCS/lib/jsf-api.jar



          <h:panelGrid columns="2" columnClasses="top,top">
          <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
          maxFilesQuantity="#{fileUploadBean.uploadsAvailable}"
          id="upload"
          immediateUpload="#{fileUploadBean.autoUpload}"
          acceptedTypes="jpg, gif, png, bmp">
          <a4j:support event="onuploadcomplete" reRender="info" />
          </rich:fileUpload>
          <h:panelGroup id="info">
          <rich:panel bodyClass="info">
          <f:facet name="header">
          <h:outputText value="Uploaded Files Info" />
          </f:facet>
          <h:outputText value="No files currently uploaded"
          rendered="#{fileUploadBean.size==0}" />
          <rich:dataGrid columns="1" value="#{fileUploadBean.files}"
          var="file" rowKeyVar="row">
          <rich:panel>
          <h:panelGrid columns="2">
          <a4j:mediaOutput element="img" mimeType="image/jpeg"
          createContent="#{fileUploadBean.paint}" value="#{row}"
          style="width:100px; height:100px;" />
          <h:panelGrid columns="2">
          <h:outputText value="File Name:" />
          <h:outputText value="#{file.name}" />
          <h:outputText value="File Length(bytes):" />
          <h:outputText value="#{file.length}" />
          </h:panelGrid>
          </h:panelGrid>
          </rich:panel>
          </rich:dataGrid>
          </rich:panel>
          <rich:spacer height="3"/>

          <a4j:commandButton action="#{fileUploadBean.clearUploadData}"
          reRender="info, upload" value="Clear Uploaded Data"
          rendered="#{fileUploadBean.size>0}" />
          </h:panelGroup>
          </h:panelGrid>

          • 2. Re: fileupload seems to have issuse  with item.getFileName()
            Phil Wilson Apprentice

            I tried the 3.2.1 snapshot and it did not work...

            http://snapshots.jboss.org/maven2/org/richfaces/ui/richfaces-ui/3.2.1-SNAPSHOT/


            that seemed to only be the ui.jar is there a place with the impl.jar too??

            Phil

            • 3. Re: fileupload seems to have issuse  with item.getFileName()
              Andrei Markavtsov Apprentice

              To upgrade from 3.2.0 to 3.2.1 you should replace richfaces-ui.jar, richfaces-api.jar and richfaces-impl.jar.

              • 4. Re: fileupload seems to have issuse  with item.getFileName()
                Phil Wilson Apprentice

                Hi Andrei,

                Thanks for your reply...

                I will upgrade the jars...where do I find them..??

                Thanks again

                Phil

                • 7. Re: fileupload seems to have issuse  with item.getFileName()
                  Phil Wilson Apprentice

                  Ok...I got a little bit more this time...


                  now it reads the file name...
                  fails on item.getData().length

                  ==============================================
                  public void listener(UploadEvent event) throws Exception{

                  System.out.println("Phil check Is file -->> : " + event.getUploadItem().isFile());

                  UploadItem item = event.getUploadItem();

                  System.out.println(" " );
                  System.out.println("item.getFileName() --->> " + item.getFileName());
                  System.out.println("item.getData().length --->> " + item.getData().length );
                  System.out.println(" " );

                  RichFile file = new RichFile();

                  System.out.println(" " );
                  System.out.println("got RichFile --->> " );
                  System.out.println(" " );

                  file.setLength(item.getData().length);
                  System.out.println(" " );
                  System.out.println("item.getData().length --->> " + item.getData().length);
                  System.out.println(" " );

                  file.setName(item.getFileName());
                  file.setData(item.getData());

                  System.out.println(" " );
                  System.out.println("item.getData() here --->> " );
                  System.out.println(" " );

                  files.add(file);

                  System.out.println(" " );
                  System.out.println("files.add file here --->> " );
                  System.out.println(" " );

                  uploadsAvailable--;

                  String out_file_name = "c:\\testPhil_121.jpg";

                  System.out.println(" " );
                  System.out.println("out_file_name --->> " + out_file_name);
                  System.out.println(" " );

                  System.out.println(" " );
                  System.out.println("item.getFileName() --->> " + item.getFileName());
                  System.out.println(" " );

                  copyUploadedFile(item.getFileName(),out_file_name );
                  }

                  =====================================

                  now it reads the file name...
                  fails on item.getData().length

                  ================================

                  2008-04-25 11:25:03,750 DEBUG org.ajax4jsf.resource.InternetResourceBuilder org.ajax4jsf.resource.InternetResourceBuilder getInstance - Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1ae9aaa

                  Phil check Is file -->> : true

                  2008-04-25 11:25:03,750 DEBUG org.ajax4jsf.resource.ResourceBuilderImpl org.ajax4jsf.resource.ResourceBuilderImpl getUri - Build URI for Resource with key [org/richfaces/renderkit/html/scripts/utils.js] as : /NetFixUp/a4j_3_2_1-SNAPSHOTorg/richfaces/renderkit/html/scripts/utils.js.jsf

                  item.getFileName() --->> philsHouse3a.jpg

                  2008-04-25 11:25:03,750 DEBUG org.ajax4jsf.resource.InternetResourceBuilder org.ajax4jsf.resource.InternetResourceBuilder getInstance - Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1ae9aaa
                  2008-04-25 11:25:03,750 DEBUG org.ajax4jsf.resource.ResourceBuilderImpl org.ajax4jsf.resource.ResourceBuilderImpl getUri - Build URI for Resource with key [org/ajax4jsf/javascript/scripts/form.js] as : /NetFixUp/a4j_3_2_1-SNAPSHOTorg/ajax4jsf/javascript/scripts/form.js.jsf
                  2008-04-25 11:25:03,765 DEBUG org.ajax4jsf.resource.InternetResourceBuilder org.ajax4jsf.resource.InternetResourceBuilder getInstance - Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1ae9aaa
                  2008-04-25 11:25:03,765 DEBUG org.ajax4jsf.resource.ResourceBuilderImpl org.ajax4jsf.resource.ResourceBuilderImpl getUri - Build URI for Resource with key [org/richfaces/renderkit/html/scripts/form.js] as : /NetFixUp/a4j_3_2_1-SNAPSHOTorg/richfaces/renderkit/html/scripts/form.js.jsf
                  2008-04-25 11:25:03,765 DEBUG org.ajax4jsf.resource.InternetResourceBuilder org.ajax4jsf.resource.InternetResourceBuilder getInstance - Return instance of internet resource builder org.ajax4jsf.resource.ResourceBuilderImpl@1ae9aaa
                  Apr 25, 2008 11:25:03 AM com.sun.faces.lifecycle.ApplyRequestValuesPhase execute
                  WARNING: org.apache.jasper.el.JspELException: /netFixFragments/profileMemberCongrats.jspf(62,12) '#{fileUploadBean.listener}' java.lang.NullPointerException
                  javax.faces.el.EvaluationException: org.apache.jasper.el.JspELException: /netFixFragments/profileMemberCongrats.jspf(62,12) '#{fileUploadBean.listener}' java.lang.NullPointerException
                  at org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor.invoke(MethodBindingMethodExpressionAdaptor.java:56)
                  at org.richfaces.component.UIFileUpload.broadcast(UIFileUpload.java:158)
                  at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:317)
                  at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:290)
                  at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:249)
                  at org.ajax4jsf.component.AjaxViewRoot.processDecodes(AjaxViewRoot.java:405)
                  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.BaseFilter.doFilter(BaseFilter.java:508)
                  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:331)
                  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.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(Unknown Source)
                  Caused by: org.apache.jasper.el.JspELException: /netFixFragments/profileMemberCongrats.jspf(62,12) '#{fileUploadBean.listener}' java.lang.NullPointerException
                  at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:77)
                  at org.richfaces.webapp.taglib.MethodBindingMethodExpressionAdaptor.invoke(MethodBindingMethodExpressionAdaptor.java:52)
                  ... 30 more
                  Caused by: java.lang.NullPointerException
                  at com.netfixup.java.util.FileUploadBean.listener(Unknown Source)
                  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
                  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
                  at java.lang.reflect.Method.invoke(Unknown Source)
                  at org.apache.el.parser.AstValue.invoke(AstValue.java:152)
                  at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                  at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
                  ... 31 more
                  2008-04-25 11:25:03,765 DEBUG org.ajax4jsf.resource.ResourceBuilderImpl org.ajax4jsf.resource.ResourceBuilderImpl getUri - Build URI for Resource with key [css/menucomponents.xcss] as : /NetFixUp/a

                  • 8. Re: fileupload seems to have issuse  with item.getFileName()
                    Andrei Markavtsov Apprentice

                    Are you sure that 'createTempFiles' parameter set up in false value in Ajax Filter?
                    If no - getData() returns null, but getFile() returns instance of temporary file created.

                    • 9. Re: fileupload seems to have issuse  with item.getFileName()
                      Andrei Markavtsov Apprentice

                      Hey. Don't worry. I see in your stack trace that 'createTempFiles' parameter set up in TRUE value: "Phil check Is file -->> : true";

                      In this case you should use getFile() method instead of getDate().

                      • 10. Re: fileupload seems to have issuse  with item.getFileName()
                        Phil Wilson Apprentice

                        ahhhh...the old change the createTempFiles....thing..


                        Works great now...thanks again for your help..

                        Phil


                        <init-param>
                        <param-name>createTempFiles</param-name>
                        <param-value>false</param-value>
                        </init-param>

                        • 11. Re: fileupload seems to have issuse  with item.getFileName()
                          Victor Bucutea Newbie

                          Did the trick for me too !!!

                          But still the correct conf is :

                           <init-param>
                           <param-name>createTempFiles</param-name>
                           <param-value>true</param-value>
                           </init-param>
                          
                          
                          
                          your last post kinda confused me a bit