Three rich:fileUpload issues.
gs_noe Jul 10, 2009 4:58 PMHi 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>