13 Replies Latest reply on Apr 18, 2008 1:11 PM by jonwelzel

    rich:fileUpload Issues

    jonwelzel

      Hi everyone.
      Before u all tell me to look at previous posts addressing this issue I'd like to say that I've been looking through this forum for a few days now and all the different topics raised here in search for help. Not just looking but trying all those tips on my project, everything to no avail though.
      So I decided to create this topic, hoping someone will be able to help me :D

      For starters, I basically copied the example available in the JBoss code sample trunk (http://anonsvn.jboss.org/repos/richfaces/trunk/samples/)

      Here's my bean:

      package beans;
      
      import java.io.ByteArrayOutputStream;
      import java.io.File;
      import java.util.ArrayList;
      import java.util.List;
      
      import org.richfaces.event.UploadEvent;
      import org.richfaces.model.UploadItem;
      
      public class uploadMB {
      
       private List itens = new ArrayList();
      
       public List getItens() {
       if (itens == null) {
       itens = new ArrayList();
       }
       return itens;
       }
      
       public void setItens(List itens) {
       this.itens = itens;
       }
      
       public void upload(UploadEvent event) {
       UploadItem item = event.getUploadItem();
       System.out.println("Arquivo : '" + item.getFileName() + "' foi enviado");
       if (item.isFile()) {
       File file = item.getFile();
       itens.add(file);
       System.out.println("Para o diretório : '" + file.getPath() + "'!");
       }
       else {
       ByteArrayOutputStream b = new ByteArrayOutputStream();
       b.write(item.getData());
       System.out.println(b.toString());
       }
       }
      }
      


      Here's my index.xhtml:
      
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core">
      <link rel="stylesheet" type="text/css" href="css/theme.css" />
      
      <style>
      .top {
       vertical-align: top;
      }
      .info {
       height: 208px;
       overflow: auto;
      }
      </style>
      
      <h:form enctype="multipart/form-data" >
       <h:panelGrid columns="2" columnClasses="top, top">
       <rich:fileUpload id="upload1"
       fileUploadListener="#{uploadMB.upload}"
       uploadData="#{uploadMB.itens}"
       addControlLabel="Adicionar"
       clearAllControlLabel="Limpar tudo"
       clearControlLabel="Limpar"
       maxFilesQuantity="5"
       reRender="table"
       uploadControlLabel="Enviar"
       immediateUpload="false"
       stopEntryControlLabel="Parar"
       acceptedTypes="jpg, gif, png, bmp, rar, zip, exe, doc"
       autoclear="false"
       stopControlLabel="Parar">
       <f:facet name="label">
       <h:outputText value="{_KB}KB de {KB}KB enviados --- {mm}:{ss}" />
       </f:facet>
       <a4j:support event="onuploadcomplete" reRender="info" />
       </rich:fileUpload>
      
       <h:panelGroup id="info">
       <rich:panel bodyClass="info">
       <f:facet name="header">
       <h:outputText value="Informacoes" />
       </f:facet>
       <rich:columnGroup>
       <h:column>
       <h:outputText styleClass="headerText" value="Arquivo" />
       </h:column>
       <h:column>
       <h:outputText styleClass="headerText" value="Tamanho" />
       </h:column>
       </rich:columnGroup>
      
       <h:column>
       <h:outputText value="#{item.fileName}" />
       </h:column>
       <h:column>
       <h:outputText value="#{item.file.length}" />
       </h:column>
      
       </rich:panel>
      
       </h:panelGroup>
      
       </h:panelGrid>
      
      </h:form>
      </html>
      


      And here's my web.xml:
      
      <?xml version="1.0"?>
      <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">
       <description>Facelets StarterKit</description>
       <display-name>Teste2</display-name>
       <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.DEVELOPMENT</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.validateXml</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>com.sun.faces.verifyObjects</param-name>
       <param-value>true</param-value>
       </context-param>
       <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>blueSky</param-value>
       </context-param>
      
       <filter>
       <display-name>RichFaces Filter</display-name>
       <filter-name>richfaces</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>10000000</param-value>
       </init-param>
       </filter>
      <filter-mapping>
       <filter-name>richfaces</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
      </filter-mapping>
      
      <filter>
       <display-name>Sleep Filter</display-name>
       <filter-name>sleepFilter</filter-name>
       <filter-class>filters.SleepDemoFilter</filter-class>
      </filter>
      <filter-mapping>
       <filter-name>sleepFilter</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       <dispatcher>ERROR</dispatcher>
      </filter-mapping>
      
       <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>
      
      <login-config>
       <auth-method>BASIC</auth-method>
      </login-config>
      </web-app>
      


      Here are my problems:
      1-My app won't work outside my IDE, if I try running this example from my browser the upload just doesn't happen.

      2-I've been trying to find a way to specify a directory inside my app server (tomcat 5.5) to where the uploaded temp files (fileName.upload) can be saved, so they're stored on my server even after it's shut down. Haven't found a way to do that yet, if u guys could enlighten me, I'd be very glad =]

      I just started messing with JSF and its implementations so be easy on me k? :P

      Thx in advance!

        • 1. Re: rich:fileUpload Issues
          simoncigoj

          Don't have a solution but a similar problem :(

          My environment :
          Apache 6.0
          Myfaces 1.2
          RichFaces 3.2.0

          Also for me the upload just doesn't happen...it never reaches the first brakepoint in my listener

          my code was posted here http://jboss.com/index.html?module=bb&op=viewtopic&t=133624

          • 2. Re: rich:fileUpload Issues
            jonwelzel

            I´m using:
            Eclipse 3.2
            Tomcat 5.5
            Richfaces 3.2.1 Snapshot (started with 3.2.0 GA)

            I´ve debugged my app, it does reach the listener breakpoints that I set up, but like I said, it won´t work outside my IDE browser, just like your problem SimonCigoj.
            Let´s hope someone here will be able to help us hehe. I´m sure other ppl are having similar problems.

            • 3. Re: rich:fileUpload Issues
              jonwelzel

              anyone?
              x]

              • 4. Re: rich:fileUpload Issues

                Please look at http://jira.jboss.com/jira/browse/RF-3096.

                There is application example attached.

                • 5. Re: rich:fileUpload Issues
                  simoncigoj

                  I tried the war from jira...it looks like it works but I havent found the source code of the bean...it contains only the build bean java code

                  tnx andrei for your help...if you coul also add source of the bean to that war it would be great

                  • 6. Re: rich:fileUpload Issues
                    jonwelzel

                    Downloaded the .war file and imported it on Eclipse. Looks ok, but like SimoCigoj I wasn't able to locate the bean hehe. I appreciate the help and if you could also make that bean available to us I'd be even glader. :D

                    Thx!

                    • 7. Re: rich:fileUpload Issues
                      jonwelzel

                      Finally got this thing working! :D
                      My solution:
                      1 - Instead of using Firefox(2.0.0.13) as my default browser I used IE7 (bleh) and the fileUpload component worked perfectly. For some unknown reason the upload just doesn't start when using Firefox (I used the Firebug plugin and it showed nonstop POST attempts going from the local machine to the server, but none were finding their way so it just kept trying and trying).
                      2 - I set the createTempFiles parameter value to "false" and used a ByteArrayOutputStream to send the byte[] from memory to a file in the server folder.

                      So now I just need to make it work on Firefox as well and then I'm all done.
                      Any suggestions as to why I'm having trouble when using Firefox?

                      Thx!

                      • 8. Re: rich:fileUpload Issues

                        I attached the source to the issue:

                        http://jira.jboss.com/jira/browse/RF-3096.


                        [/url]

                        • 9. Re: rich:fileUpload Issues

                          Jonwelzel,

                          The fileupload componetn's behavior is the same in different browsers.

                          We have not detected that FU does not work in FF.

                          Anyway I can attach FF version that I use ==)

                          To solve the problem please try to clear cache.

                          If you still have the problem I will be awaiting detailed info from you.
                          You can post it into JIRA with screenshots.

                          Thank you.

                          • 10. Re: rich:fileUpload Issues
                            jonwelzel

                             

                            "andrei_exadel" wrote:
                            Jonwelzel,

                            The fileupload componetn's behavior is the same in different browsers.

                            We have not detected that FU does not work in FF.

                            Anyway I can attach FF version that I use ==)

                            To solve the problem please try to clear cache.

                            If you still have the problem I will be awaiting detailed info from you.
                            You can post it into JIRA with screenshots.

                            Thank you.



                            Hi Andrei, thx for the help.
                            I did clear the FF cache but still had the same problem.
                            I posted the issue into JIRA along with two screenshots showing what's happening.
                            Here's the link: http://jira.jboss.com/jira/browse/RF-3127

                            Thx!!

                            • 11. Re: rich:fileUpload Issues

                              Hi Jon,

                              I looked on your example attached.

                              The problem is absence of tag on you page containing file upload component.

                              Please include tag. I sure it should solve the problem.

                              Thank you for posting. We will add this requirements to guide.

                              • 12. Re: rich:fileUpload Issues

                                Correct to my previous post:

                                We will not add this to guide, because 'body' tag is mandatory according to W3C spec.

                                • 13. Re: rich:fileUpload Issues
                                  jonwelzel

                                   

                                  "andrei_exadel" wrote:
                                  Correct to my previous post:

                                  We will not add this to guide, because 'body' tag is mandatory according to W3C spec.



                                  Either way Andrei, thx so much for your help!!
                                  It works perfectly on both browsers now :D
                                  If only I had checked the w3c website lol

                                  Cya!