4 Replies Latest reply on Aug 27, 2013 5:44 PM by bleathem

    Getting feedback from rich:fileUpload listener for each file from listener

    vrockai

      Hi,

       

      I'm using RF 4.3.x and I'm struggling with something which may be pretty common use-case - feedback from the rich:fileUpload component for each file separately. We're processing each file in fileUploadListener, but some files may be corrupted, or just invalid in general. I'm looking for a way how to provide a feedback for the user, not only about the uploading itself, but even if the processing of file in listener has succeeded. Actually, my goal is to change the color in the rich:fileUpload file list to green if everything is OK or change the color to red and provide relevant error message if an exception was thrown in the listener.

       

      Is there a common/good practice way to do that?

       

      Thanks,

       

      Viliam

        • 1. Re: Getting feedback from rich:fileUpload listener for each file from listener
          bleathem

          How about adding a new FacesMessage from your fileUploadListener?

          • 2. Re: Getting feedback from rich:fileUpload listener for each file from listener
            pmensik

            Or, in case that you are using CDI in you application, you could  fire a CDI event in your listener and then make some appropriate reaction based on your event in the observer.

            • 3. Re: Re: Getting feedback from rich:fileUpload listener for each file from listener
              vrockai

              Maybe I just don't know how to use that correctly. If the info below is not the way you had in your mind, please give me more hints.

               

              I don't know how to resolve this in an elegant way using message. The way I know about using FacesMessage is something like this:

              final FacesContext context = FacesContext.getCurrentInstance();
              final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, filename, null);
              context.addMessage(component.getClientId(), facesMsg);
              

               

              But this is restricted to request, so at one time, I've got information only about single file. What comes to my mind is storing the list of invalid files in a bean (when listener gets an error, it'll add the currently processed filename to the list). The last part of listener would consists of adding the file names from that list to the context messages. But parsing messages with JS and updating the file list in uploader seems a bit overkill (+ troubles with clearing the file uploader list).

              • 4. Re: Getting feedback from rich:fileUpload listener for each file from listener
                bleathem

                Viliam Rockai wrote:

                 

                1. final FacesContext context = FacesContext.getCurrentInstance(); 
                2. final FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, filename, null); 
                3. context.addMessage(component.getClientId(), facesMsg); 

                 

                That's what I was thinking.  Am I understanding you correctly in that you don't like this solution because it gives feedback one file at a time, and you would rather display the feedback altogether after some processing has occurred?  This seems contrary to your original request for "feedback from the rich:fileUpload component for each file separately".  There is likely something I am missing.

                 

                As for a workaournd to the immediate problem you described, You could store the clientId and the message text in a bean, and create the FacesMessages when you are ready for them to be displayed.

                 

                If this is not sufficient, please clearly described your use case, and we'll see if we can uncover a feature request.