4 Replies Latest reply on Apr 25, 2008 5:06 AM by Andrei Markavtsov

    fileUpload problem

    Paulo Vitor Braga Pessoa Newbie

      Hi guys,
      Im tryng to implement richfaces file upload and I get one error.
      When the file comes in my bean, the byte array of my file is null, but the FileName is OK!
      heres my configuration,
      WEB.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
       <display-name>InventarioServicos</display-name>
       <!-- SPRING -->
       <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/applicationContext.xml</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.REFRESH_PERIOD</param-name>
       <param-value>2</param-value>
       </context-param>
       <context-param>
       <param-name>facelets.LIBRARIES</param-name>
       <param-value>
       /WEB-INF/facelettl.xml
       </param-value>
      </context-param>
      
       <!--
       <context-param>
       <param-name>org.richfaces.LoadStyleStrategy</param-name>
       <param-value>NONE</param-value>
       </context-param>
       -->
       <context-param>
       <param-name>org.ajax4jsf.SKIN</param-name>
       <param-value>mcpInventario</param-value>
       </context-param>
       <filter>
       <filter-name>jpaFilter</filter-name>
       <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
       </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>false</param-value>
       </init-param>
       <init-param>
       <param-name>maxRequestSize</param-name>
       <param-value>20000000</param-value>
       </init-param>
       </filter>
       <filter-mapping>
       <filter-name>jpaFilter</filter-name>
       <url-pattern>/*</url-pattern>
       </filter-mapping>
       <filter-mapping>
       <filter-name>ajax4jsf</filter-name>
       <servlet-name>FacesServlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>
       <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
       <listener>
       <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
       </listener>
       <servlet>
       <servlet-name>FacesServlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
       <servlet-mapping>
       <servlet-name>FacesServlet</servlet-name>
       <url-pattern>/faces/*</url-pattern>
       </servlet-mapping>
       <servlet-mapping>
       <servlet-name>FacesServlet</servlet-name>
       <url-pattern>*.jsf</url-pattern>
       </servlet-mapping>
      
       <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
       </welcome-file-list>
       <login-config>
       <auth-method>BASIC</auth-method>
       </login-config>
      
      
      </web-app>
      
      


      my xhtml:
      <rich:fileUpload fileUploadListener="#{formulario.listenerUpload}"
       maxFilesQuantity="1"
       uploadData="#{formulario.files}"
       listWidth="200px"
       listHeight="100px"
       reRender="painelUpload"
       id="upload"
       >
       <a4j:support event="onuploadcomplete" reRender="info" />
       </rich:fileUpload>
      


      and my bean:

      public void listenerUpload(UploadEvent event) throws IOException{
       UploadItem item = event.getUploadItem();
      
       Upload.upload(item.getFileName(), item.getData());
       File f = new File("asd");
      
       System.out.println("File : '" + item.getFileName() + "' was uploaded");
       /*if (item.isFile()) {
       File file = item.getFile();
       System.out.println("Absolute Path : '" + file.getAbsolutePath() + "'!");
       }
       else {
       ByteArrayOutputStream b = new ByteArrayOutputStream();
       b.write(item.getData());
       System.out.println(b.toString());
       }*/
       }
      

      somebody can help me?
      I lost all day tryng to solve this problem :(
      tranks.. and sorry for the bad english

        • 1. Re: fileUpload problem
          Phil Wilson Apprentice

          Did you get this working?

          I have the same issue.


          Phil

          • 2. Re: fileUpload problem
            Yurii Kartsev Apprentice

            Hey!

            I've got everything working to me. I know that "event.getUploadItem().getData()" is null and the "event.getUploadItem().getFileName()" is NOT null(just as getFile()), happens only when createTempFiles parameter in web.xml is true. But you have it false - it's a nonsense.

            Try this in your listener:

            System.out.println("Is file: " + event.getUploadItem().isFile());

            just to be sure about createTempFiles value. What does it say?

            • 3. Re: fileUpload problem
              Phil Wilson Apprentice

              Hi J-Pro,

              Thanks for your reply...

              Output from

              Phil check Is file -->> : false

              item.getFileName() 11 --->> null

              =======================================
              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() 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--;

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

              web.xml


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

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

              I changed the parm-value to false same issue.


              Phil

              This was my post before with my code...

              http://jboss.com/index.html?module=bb&op=viewtopic&t=134419


              • 4. Re: fileUpload problem
                Andrei Markavtsov Apprentice

                nohacks,

                Can you please specify what RF version do you use for test?

                We recommend to use 3.2.1. This caused by many issues in 3.2.0.

                If you have problems with 3.2.0 try 3.2.1. It should work.

                Thanks.