12 Replies Latest reply on Apr 14, 2008 5:58 PM by Tim Goodchild

    Empty UploadItem when using fileUpload

    Tim Goodchild Newbie

      I've been pulling my hair out all day trying to get the fileUpload to work for RichFaces 3.2.0 with facelets 1.1.14.

      I practically copied the exadel live demo but in the listener method I get an UploadItem from the UploadEvent, where the bytes, file and filename attributes are all null.

      I just can't see what I'm doing wrong:-

      web.xml :


      xhtml form:-

       <h:form id="userProfilePhotoUpload">
       <h:panelGrid columns="2" columnClasses="top,top">
       <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
       reRender="table" id="upload"
       acceptedTypes="jpg, gif, png, bmp">
       <a4j:support event="onuploadcomplete" reRender="info" />
       <h:panelGroup id="info">
       <rich:panel bodyClass="info">
       <f:facet name="header">
       <h:outputText value="Uploaded Files Info" />
       <h:outputText value="No files currently uploaded"
       rendered="#{fileUploadBean.size==0}" />
       <rich:dataGrid columns="1" value="#{fileUploadBean.files}"
       var="file" rowKeyVar="row">
       <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}" />
       <rich:spacer height="3"/>
       <br />
       <a4j:commandButton action="#{fileUploadBean.clearUploadData}"
       reRender="info, upload" value="Clear Uploaded Data"
       rendered="#{fileUploadBean.size>0}" />

      public class FileUploadBean
       private ArrayList<File> files = new ArrayList<File>();
       private int uploadsAvailable = 5;
       private boolean autoUpload = false;
       public int getSize()
       if (getFiles().size() > 0)
       return getFiles().size();
       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 IOException
       UploadItem item = event.getUploadItem();
       File file = new File();
       public String clearUploadData()
       return null;
       public ArrayList<File> getFiles()
       return files;
       public void setFiles(ArrayList<File> files)
       this.files = files;
       public int getUploadsAvailable()
       return uploadsAvailable;
       public void setUploadsAvailable(int uploadsAvailable)
       this.uploadsAvailable = uploadsAvailable;
       public boolean isAutoUpload()
       return autoUpload;
       public void setAutoUpload(boolean autoUpload)
       this.autoUpload = autoUpload;


      If you can see whats going wrong here I'd be really grateful..