0 Replies Latest reply on Oct 4, 2011 6:47 AM by leesy

    [rich:fileUpload] Throwing Errors In UploadListener

    leesy

      Hi all,

       

      I'm in the process of upgrading an upload page (that uses rich:fileUpload) to use a virus scanner to double check any files being uploaded.  At the moment, I've managed to get it to display an error via FacesMessages.  This is fine but what I'd really like is to be able to change the status of the uploaded file from "Done" to something else, even invoking the transfer error state would be good enough.  But I can't seem to figure out how I might do this.  If I throw an exception, the item in the upload still shows only "Done".

       

      Does anyone know the best way of marking an uploaded item as errored via my upload listener?  Or is there a better way of doing what I want?  I'm using JSF2 & RichFaces 4.0, so am I able to use the <f:event/> tag to get what I want? I'm trying that now but am still having no luck.

       

      Here's the code I have at the moment but all this does is show a FacesMessage at the moment:

       

      {code}public void uploadListener(FileUploadEvent event) throws Exception {

          UploadedFile item = event.getUploadedFile();

       

          // Fix for IE sending full file path

          String itemName = item.getName();

          if (itemName != null) {

            itemName = FilenameUtils.getName(itemName);

          }

       

          // Scan for viruses!

          try {

            scanEngineProxy.scanFile(itemName, item.getData());

       

            log.debug("Uploading file into " + collection);

            mediaFileDAO.createFile(itemName, item.getData(), collection);

          } catch (ScanException e) {

                  FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Details: " + e.toString(),

                      "A virus was detected in file "+ itemName));

                  throw e;

          }

      }{code}

       

      Cheers for any input,
      Lee