4 Replies Latest reply on Oct 12, 2009 10:55 AM by Tathagat Tathagat

    rich:fileUpload - cancel upload from listener method and sho

    Tathagat Tathagat Newbie

      Hi all.
      My situation is as follows:

      I upload the file to DB (works wonderfully). Now I want to check if the file (name constraint) already exists in the DB. If yes, I want to cancel the upload and show the user an error message. How can I do it?

      I tried this:

      public void uploadDocument(UploadEvent event) throws Exception{
       UploadItem item = event.getUploadItem();
       logger.debug("uploadDocument: " + item.getFileName() + ":" + item.getFile() + ":" + item.getFileSize()
       + ":" + item.getContentType());
      
       if (checkFileExistsInDb(item.getFileName())) {
       FacesMessages.instance().addToControl("documentUpload", Severity.ERROR, "This file already exists!", new Object());
       } else {
       //do the uploade
       }
      }


      This error message never shows up.

      Thanks in advance for your help.

      Regards
      Tathagat