5 Replies Latest reply on Nov 23, 2009 1:18 PM by devnulled

    fileUpload problem - error message is not displayed

    hrast200

      Hi!

      I would like to know is there a way to stop fileUploadListener (fileUpload component) and diplay error message?

      E.g.
      I would like to upload file only if file with sam name doesn't egsist on server. It would be nice if the validation would be on client side. So I tried to do validation inside of fileUploadListener, but the message (<h:messages />) is not shown, although the upload is stopped, and message is added.

      Here is the code

      public void processUpload(UploadEvent event) {
      
       UploadItem item = event.getUploadItem();
       java.io.File f = item.getFile();
      
       fileList = getFiles();
       for (File file : fileList) {
       if(item.getFileName().equals(file.getName())){
       FacesContext ctx = FacesContext.getCurrentInstance();
       //Show message
       ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
       "error", "error"));
      
      
       ctx.renderResponse();
       return;
       }
       }
       //If file doesn't egsists...
       ...