9 Replies Latest reply on Sep 22, 2009 5:36 PM by Greg Noe

    Three rich:fileUpload issues.

    Greg Noe Newbie

      Hi All,

      I'm having a couple issues with the rich:fileUpload component.

      Problem #1: When using the flash module for multi-file uploads, the Add button is disable upon the first page load. The page must be reloaded for the Add button to be enabled. I can reproduce this in IE7 and FF3.0.11. I have tried the following to get it to work:

      - Set the value of the "maxFilesQuantity" attribute using a bean field, and by hard coding an integer value.
      - Set the "disabled" attribute to false using a field in my file upload bean, and by hard coding "false".

      Problem #2: When trying to do multiple file uploads with the flash module in an HTTPS session using Firefox 3.0.11 the rich:fileUpload component shows Transfer error occurred and quits uploading. I don't see any errors in Firebug or in my web server console. I've also watched the session through Fiddler and don't see any errors there either. The non-flash uploader doesn't have this problem and IE 7 doesn't have this problem with the normal or the flash module.

      Any ideas?

      My environment:

      RichFaces Version: 3.3.1 GA
      Web Server: Tomcat 6.0.18

      The HTML:

      <rich:fileUpload
       fileUploadListener="#{photoToPDFBean.listener}"
       allowFlash="#{photoToPDFBean.useFlash}" --- Always "true"
       disabled="#{photoToPDFBean.controlDisabled}" --- Always "false"
       maxFilesQuantity="#{photoToPDFBean.uploadsAvailable}" --- Defaults to "20"
       uploadData="#{photoToPDFBean.uploadData}" --- List of UploadItem
       id="upload"
       autoclear="false"
       immediateUpload="false"
       acceptedTypes="jpg, gif, png, bmp">
       <a4j:support event="onuploadcomplete" reRender="info" />
      </rich:fileUpload>
      


      The (important) Java stuff:
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.faces.context.FacesContext;
      import javax.servlet.http.HttpServletResponse;
      
      import org.apache.commons.io.FileUtils;
      import org.apache.commons.io.FilenameUtils;
      import org.apache.commons.lang.StringUtils;
      import org.richfaces.event.UploadEvent;
      import org.richfaces.model.UploadItem;
      
      import com.company.java.web.report.util.pdf.PageNumbersWatermark;
      import com.company.java.web.utils.CompanyDateUtil;
      import com.company.java.web.utils.JsfUtils;
      import com.company.java.web.utils.upload.ImageUploadFile;
      
      public class PhotoToPDFBean {
      
       private boolean controlDisabled = false;
       private boolean useFlash = true;
       private List<ImageUploadFile> files;
       private int uploadsAvailable = 20;
       private List<UploadItem> uploadData;
      
       /**
       * Constructor for PhotoToPDFBean
       */
       public PhotoToPDFBean() {
       // Auto-generated constructor stub
       }
      
       /**
       * Getter for the files.
       * @return the List<ImageUploadFile> : files
       */
       public final List<ImageUploadFile> getFiles() {
       if (null == this.files) {
       this.files = new ArrayList<ImageUploadFile>();
       }
       return this.files;
       }
      
       /**
       * Setter for the files.
       * @param files the files to set
       */
       public final void setFiles(List<ImageUploadFile> files) {
       this.files = files;
       }
      
       /**
       * Getter for the uploadsAvailable.
       * @return the int : uploadsAvailable
       */
       public final int getUploadsAvailable() {
       return this.uploadsAvailable;
       }
      
       /**
       * Setter for the uploadsAvailable.
       * @param uploadsAvailable
       */
       public final void setUploadsAvailable(int uploadsAvailable) {
       this.uploadsAvailable = uploadsAvailable;
       }
      
       /**
       * Gets the number of files that have been uploaded.
       * @return
       */
       public int getFileCount() {
       if (getFiles().size() > 0) {
       return getFiles().size();
       } else {
       return 0;
       }
       }
      
       /**
       * Upload event listener for adding files to the list.
       * @param event
       * @throws Exception
       */
       public void listener(UploadEvent event) throws IOException {
       UploadItem item = event.getUploadItem();
       ImageUploadFile file = new ImageUploadFile();
       file.setName(FilenameUtils.getName(item.getFileName()));
       file.setData(FileUtils.readFileToByteArray(item.getFile()));
       file.setLength(file.getData().length);
       getFiles().add(file);
       this.uploadsAvailable--;
       }
      
       /**
       * Method to get file content.
       * @param stream
       * @param object
       * @throws IOException
       */
       public void paint(OutputStream stream, Object object) throws IOException {
       stream.write(getFiles().get((Integer)object).getData());
       }
      
       /**
       * Method to clear uploaded files.
       */
       public String clearFileAction() {
       getFiles().clear();
       setUploadsAvailable(20);
       setPdfTitle("");
       setPdfDescription("");
       return null;
       }
      
      
      
       /**
       * Getter for the upload data
       * @return the uploadData
       */
       public final List<UploadItem> getUploadData() {
       if (null == this.uploadData) {
       this.uploadData = new ArrayList<UploadItem>();
       }
       return uploadData;
       }
      
       /**
       * Setter for the upload data.
       * @param uploadData the uploadData to set
       */
       public final void setUploadData(List<UploadItem> uploadData) {
       this.uploadData = uploadData;
       }
      
      }
      
      
      


      web.xml:
       <filter>
       <display-name>Ajax4jsf Filter</display-name>
       <filter-name>ajax4jsf</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
       <init-param>
       <description>Maximum uploadable file size.</description>
       <param-name>maxRequestSize</param-name>
       <param-value>1000000</param-value>
       </init-param>
       <init-param>
       <description>Creates temporary files on disk.</description>
       <param-name>createTempFiles</param-name>
       <param-value>true</param-value>
       </init-param>
       </filter>
      




        • 1. Re: Three rich:fileUpload issues.
          Kavita Tipnis Newbie

          I had the exact issue as your Problem# 1.
          My workaround for that was to 'reRender' the fileupload component.
          It works in IE and FF(not tested on any other browsers) I have used richfaces 3.3.0 GA.

          • 2. Re: Three rich:fileUpload issues.
            Greg Noe Newbie

            Oops. Only two issues, not three...

            • 3. Re: Three rich:fileUpload issues.
              Greg Noe Newbie

               

              "kavitatipnis" wrote:
              I had the exact issue as your Problem# 1.
              My workaround for that was to 'reRender' the fileupload component.
              It works in IE and FF(not tested on any other browsers) I have used richfaces 3.3.0 GA.


              'reRender' from what component/on what event?

              Thanks,

              - G



              • 4. Re: Three rich:fileUpload issues.
                Ilya Shaikovsky Master

                1) wanted to advice to check latest snapshot. But, bad news, seems the things even worth there :)
                https://jira.jboss.org/jira/browse/RF-7523

                check after resolution.

                2) Some browsers restricts number of opened http connections. This could be cause of wrong behavior.

                • 5. Re: Three rich:fileUpload issues.
                  Kavita Tipnis Newbie

                   

                  'reRender' from what component/on what event?


                  reRender your fileUpload after'onuploadcomplete' event.

                  <a4j:support event="onuploadcomplete" reRender="info,upload"/>



                  • 6. Re: Three rich:fileUpload issues.
                    Greg Noe Newbie

                     

                    "kavitatipnis" wrote:
                    reRender your fileUpload after'onuploadcomplete' event.

                    <a4j:support event="onuploadcomplete" reRender="info,upload"/>



                    I have that in place but the "Add" button is still disabled (when using the Flash based uploader) when the page is first rendered in FireFox, IE and Opera. The only browser that the button is enabled on its initial load is Chrome.

                    I tried the latest RichFaces version (3.3.2 CR1) and that doesn't help either.

                    Also, the flash-based upload component still doesn't work in FireFox, Opera or Chrome when using HTTPS. Upon further research, it looks like a problem with Flash possibly not being able to use self-signed security certificates in non-IE browsers. It would make sense because I'm using self-signed security certificates while developing my application. I guess we'll see what happens when we go to production with a real certificate.

                    • 7. Re: Three rich:fileUpload issues.
                      Nick Belaevski Master

                      Hi,

                      What is Flash player version and OS?

                      • 8. Re: Three rich:fileUpload issues.
                        Greg Noe Newbie

                         

                        "nbelaevski" wrote:
                        Hi,

                        What is Flash player version and OS?


                        Windows XP SP-3
                        Flash 10.0.32.18 (The latest)

                        • 9. Re: Three rich:fileUpload issues.
                          Greg Noe Newbie

                          Ok, so I've given up on getting the flash based uploader to work in any browser but IE under HTTPS. I don't think it is a RichFaces issue.

                          As for the "Add" button being disabled upon the initial page load, I still haven't figured out why it won't work.

                          I tried adding the a4j:jsFunction that is called from the oncomplete attribute from the a4j:commandLink that brings up the upload page:

                          
                          <a4j:jsFunction action="#{photoToPDFBean.dummyAction}" name="checkUpload" reRender="upload" limitToList="true"/>
                          
                          


                          When this is called the rich:fileUpload component re-renders, flickers as if it is enabled, then goes back to being disabled. It seems as if the ONLY way the component gets enabled is by refreshing the whole page.

                          Could the fact that the upload page content is rendered inside/through a4j:outputPanels and a4j:includes be an issue?