6 Replies Latest reply on Apr 23, 2014 6:32 AM by Artur Mig

    rich:fileUpload - always correct file status

    Artur Mig Newbie

      Hello,

      I have the following problem with the control rich: FileUpload.

      Sending files generally works correctly, but not running error handling.

      When there is an exception during the shipping of the file status in the control is always correct.

      You do not have the information that something went wrong.

      So the question is, how can I pass the control that the operation failed (eg there was 'transferError').

      I'm sorry, but I still have a lot of experience.

       

       

       

          public void listener(UploadEvent event) {
              if (event != null || event.getUploadItem() != null) {
                  try {
                      UploadItem item = event.getUploadItem();
                      handleUpload(item);
                  } catch (Exception e) {
                      logger.error("Error: " + e);
                  }
              }
          }
      
      
        • 1. Re: rich:fileUpload - always correct file status
          Michal Petrov Master

          Hi,

           

          I'm not sure I understand your problem. Does the exception occur before the listener is called? Or are you trying to let the user know something happened inside the listener?

          • 2. Re: rich:fileUpload - always correct file status
            Artur Mig Newbie

            Option 2, which I'm going to tell the user that the operation performed within the method 'listener' failed.

            When I turn bug with 'try / catch', in the control the user has information that the file upload operation went fine.

             

            I should add that I use RichFaces 3.3.1

            • 3. Re: Re: rich:fileUpload - always correct file status
              Michal Petrov Master

              I see. Your listener is not part of the file upload process. The upload ends when the file gets to the server, after that the listener is triggered.

               

              If you want to tell the user something went wrong in your method you have to implement your own way of doing it, in the photoalbum demo we use this:

              public static void addFacesMessage(String componentId, String summary, String detail) {
                  UIComponent root = FacesContext.getCurrentInstance().getViewRoot();
                  UIComponent component = root.findComponent(componentId);
                  FacesContext.getCurrentInstance().addMessage(component.getClientId(FacesContext.getCurrentInstance()),
                      new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail));
              }
              

               

              You can then use a <rich:message> or <rich:notifyMessage> that will display the error:

              <r:notifyStack direction="vertical" position="topLeft" id="stack">
                  <r:notifyMessages for="overForm" styleClass="photoalbum-message" sticky="true" stack="stack" showDetail="true" showSummary="true" />
              </r:notifyStack>
              
              • 4. Re: Re: rich:fileUpload - always correct file status
                Artur Mig Newbie

                Thank you for your response.

                I understand that my situation is not possible to display the component 'rich: FileUpload' transferErrorLabel instead doneLabel to let you know which files have been sent.

                 

                Therefore, the answer must be in a different type of component messages. Only in my version of FF (3.3.1) there is a problem with the submit form.

                When you click 'Upload' does not appear to me message. So I tried to add a separate button to send:


                <a4j:commandButton  id="uploadFormButton" 

                value="Send" 

                onclick="#{rich:component('fileUploadId')}.submitForm();" 

                oncomplete="#{rich:component('fileUploadId')}.clear();"/>

                 

                ...but then I lose the animation on a component in the shipping cycle files.

                Is there a possibility to use the 'Send' button on the component 'rich: FileUpload' and receive an answer in component 'h: messages'?

                • 5. Re: Re: rich:fileUpload - always correct file status
                  Michal Petrov Master

                  I'm not sure I understand. You put files into the fileUpload and you click "Upload". What do you want to happen next?

                  • 6. Re: Re: rich:fileUpload - always correct file status
                    Artur Mig Newbie

                    I put files into the FileUpload and you click " Upload" .

                    All files are sent .

                    At the end I want to draw a message to 'h : messages ', but I do not get it .

                    As you can see this message ?

                     

                    <rich:fileUpload fileUploadListener="#{$bean$.listener}"

                        id="fileUploadId" allowFlash="false"

                        <a4j:support event="onfileuploadcomplete" reRender="messages" />

                    </rich:fileUpload>

                     

                    <h:messages id="messages" />

                     

                     

                    I would add that the message appears correctly when I use another button to review the form for approval:

                     

                    <a4j:commandButton  id="uploadFormButton"

                      value="Send"

                      onclick="#{rich:component('fileUploadId')}.submitForm();"

                      oncomplete="#{rich:component('fileUploadId')}.clear();"/>