4 Replies Latest reply on Mar 23, 2011 5:54 AM by Ilya Shaikovsky

    RichFaces 4.0 CR1 and fileUpload

    Enrique Fagoaga Newbie

      Hi there.

      I'm trying to upload a single file using Richfaces 4. I've noticed that the rich:fileUpload attribute maxFilesQuantity has been removed. Taking a look into JIRAs and Wikis, it seems that it is not going to be included in the final version.

       

      Currently we are using JSF2 and RichFaces, one of my application requirements is to upload a single file to the system, can anyone guide/help me to do it?.

       

       

      Thanks a lot in advance!

        • 1. RichFaces 4.0 CR1 and fileUpload
          Ilya Shaikovsky Master

          just make the component not rendered after succesfull file upload (using onuploadcomplete), or navigate to the  results page.. different options could be used according to your needs.

          • 2. RichFaces 4.0 CR1 and fileUpload
            Enrique Fagoaga Newbie

            Hi Iliya, first of all, thanks four your answer.

             

            But the user will be allowed to 'add' a lot of files that will be listed in the rich:fileUpload component, of course after the first successful upload I can hide the component, but it does not seams a good approach... (The user adds 6 files, press upload, system process the first file but ignore the rest, component is hide)

             

            I've tried to hide the 'add' button after the user press on it, however I am not able to detect if he clicks on "Cancel" in the browser dialog for selecting the file. Because if he does, the 'add' button won't be enabled anymore.

             

            Do you have any other ideas?

            I will continue investingating, thanks for your support.

            • 3. Re: RichFaces 4.0 CR1 and fileUpload
              Enrique Fagoaga Newbie

              Hi All,

               

              I finally achieve what I were looking for. I have to override the uploadButton show & hide methods. What I'm doing in the code below is to hide Add button when Upload button is displayed, and display Add button when Upload button is hided.

               

              In this way, user is only available to add one item to the upload files list.

               

              $(document).ready(function(){
              
                    var oldShowUploadFunction = #{rich:component('uploadId')}.uploadButton.css;
                     // Define overriding method.
                     #{rich:component('uploadId')}.uploadButton.css = function(name, value){
              
                                #{rich:component('uploadId')}.addButton.hide();
                                 // Execute the original method.
                                 oldShowUploadFunction.apply(this, arguments);
                      };
              
                      var oldHideUploadFunction = #{rich:component('uploadId')}.uploadButton.hide;
                       // Define overriding method.
                      #{rich:component('uploadId')}.uploadButton.hide = function(){
              
                                  #{rich:component('uploadId')}.addButton.show();
                                  // Execute the original method.
                                  oldHideUploadFunction.apply(this, arguments);
                       };
               });
              
              • 4. Re: RichFaces 4.0 CR1 and fileUpload
                Ilya Shaikovsky Master

                sorry.. do not thought about that :)

                 

                Yup.. unfortunatelly for now you have to use workaround you listed.. because FU even have no handlers like onadd onremove in order to invoke custom JS which will be able to show/hide the buttons.

                 

                P.S. will include that into checklist while reviewing requirements for future versions for sure.