1 2 3 4 Previous Next 56 Replies Latest reply on Sep 19, 2013 9:57 AM by haseeb Go to original post
      • 15. Re: workaround for multipleUpload capability in <rich:fileUpload>
        lfryc

        One more thing, have you tried the changes across different browsers?

         

        I have one specific concern - does the file upload work correctly if you do repeated selection of multiple files? e.g.:

        1. select 5 files

        2. select 1 file

        3. select 3 files

         

        I just guess this use case can be tricky one. :-)

        1 of 1 people found this helpful
        • 16. Re: workaround for multipleUpload capability in <rich:fileUpload>
          simone.83

          Yes, i'll doing the tests and all seems to be ok in a simple web-app with <rich:fileUpload>, but with another web-app i'm having some troubles with this one.

          I'm investigating on that [-->when the immediateUpload is set, the files are loaded in history list but only one of them haves a progress bar associated and the clear link <--]

          ...I promise that I will fix and correct all source code (eventually) bugs.

           

          My great problem is that: I'm doing the tests with a my .jar version of  richfaces-components-ui-4.3.1.Final.jar (in attachments) where I've tryed to change all fileupload.js inside

          the various directories. Then I upload this file inside my environment replacing the original .jar file inside WEB-INF/lib/. It seems to work but I still use the extended classes

          declared within the faces-config.xml  using <render-kit>. For generating .class file and make a real test I have to spend time to create an environment for build direcly from the sources

          of RichFaces,and now I can't do It here at work.

           

          For the Contributors license agreement, when I try to register myself the form requests an eventually Jira ticket associated...have you ever opened any Jira about this issue?

          I remember a Jira ticket about this problem opened by someone, but now I'm in full immersion with source code and if I start to search on the web I think my brain will enter in kernel panic...

          ...if you have this Jira ticket please give me the Id. I'll refresh you later ok?? Thank you Lukáš

          • 17. Re: workaround for multipleUpload capability in <rich:fileUpload>
            lfryc

            Simone, there is another "hacky" way how to improve this "testing workflow":

             

            If you will put the changes files to correct positions in the sample WAR, the JSF runtime will pick them with priority over Java/JavaScript files in a richfaces.jar.

             

            You can save/edit/preview almost immediately. I have tried this several times with JBoss AS and it worked - it might work for you as well.

             

            I believe the right locations for changed files are:

             

            {WAR}/resources/org.richfaces/fileupload.js

            {WAR}/WEB-INF/classes/org/richfaces/renderkit/FileUploadRendererBase.class

            {WAR}/WEB-INF/classes/org/richfaces/renderkit/FileUploadRenderer.class

             

            Even if it haven't worked, you can use RichFaces Resource Mapping to include patched version of JavaScript:

            http://lukas.fryc.eu/blog/2012/02/re-routing-jsf-resource-requests-with.html

            • 18. Re: workaround for multipleUpload capability in <rich:fileUpload>
              lfryc
              • 19. Re: workaround for multipleUpload capability in <rich:fileUpload>
                simone.83

                All done with the Contributors License Agreement, and made the association with RF-12224 ! I've some problems with testing: i'll try to explain briefly...

                I've two war files. The first is a simple project with an .xhtml file with the same content of the fileupload showcase example, and a much more complex project (the project where I'm involved at work). I've replaced all the fileupload.js files inside the richfaces-components-ui-4.3.1.Final.jar and then replaced this jar with the other one in lib directory of the war project, and then deployed manually in JBoss AS 7.0 and then in EAP 6.1. The results are the same: the first, simplest project works fine and well. The last, much more complicated project haven't the expected behaviour...it sends well the uploaded files at bean-side but I see only one item-per-time inside the history, differently from the first one. I've also tried your suggestions http://lukas.fryc.eu/blog/2012/02/re-routing-jsf-resource-requests-with.html

                but the results are the same. I've tried to change inside the web.xml:

                 


                <context-param>


                <param-name>javax.faces.PROJECT_STAGE</param-name>


                <param-value>Production</param-value>

                </context-param>

                 

                to

                 


                <context-param>


                <param-name>javax.faces.PROJECT_STAGE</param-name>


                <param-value>Development</param-value>

                </context-param>

                 

                but nothing to do...

                As last, I also tried to put the simple .xhtml file and beans of the first, simplest, project inside the much more complicated project and the result is

                that will not work too calling simple .xhtml page. It seems to be like a malediction of .war...Help me ... how can I do ?

                 

                PS: for the .class, i still use my classes extended from the base classes, specifying them using the <render-kit>: in fact, in either .war tests the bean

                side works perfectly...

                • 20. Re: workaround for multipleUpload capability in <rich:fileUpload>
                  lfryc

                  Is it possible that you have Resource Optimization turned on?

                  http://docs.jboss.org/richfaces/latest_4_X/Developer_Guide/en-US/html/chap-Developer_Guide-Advanced_features.html#sect-Developer_Guide-Advanced_features-Resource_optimization

                   

                  Let's check in the browser development tools whether the actual patched fileupload.js is loaded (Source view).

                  1 of 1 people found this helpful
                  • 21. Re: workaround for multipleUpload capability in <rich:fileUpload>
                    simone.83

                    woooooooooooonderful...it works!!!!!!! hahahahaha

                    yeah! guess what? .. it was the damned resource mapping setted to true :

                     

                        <context-param>

                            <param-name>org.richfaces.resourceMapping.enabled</param-name>

                            <param-value>true</param-value>

                        </context-param>

                     

                    Now, i've set to false and all works perfectly.

                    So yes, i had a sort of resource optimization turned on, thanks for your support Lukáš you are a very great guy I think!.

                    Now all it's perfectly like a dream I can't believe that all it's true:

                    this is the first time in over tean years of computer science studies I made something of useful for anyone different to my professors. It's wonderful!

                     

                    Thank you for support and patience and thanks to the whole community!

                    • 22. Re: workaround for multipleUpload capability in <rich:fileUpload>
                      simone.83

                      Now I can reply to your test proposal (first with 2 files, then with 5 files etc etc): yes, it seems to work perfectly in these cases.

                      I still remain available for anyother suggestion, until the 4.3.3 release is done and my patch works as we expect ok?

                      • 23. Re: workaround for multipleUpload capability in <rich:fileUpload>
                        lfryc

                        Hey Simone, that's great! It is my pleasure to help you! :-)

                         

                        I'm already targetting RF-12224 to 4.3.3!

                         

                        Don't forget to push a pull request with final versions of fileupload.js and other files (if you updated them).

                         

                        Keep an awesome work!

                        • 24. Re: workaround for multipleUpload capability in <rich:fileUpload>
                          simone.83

                          Yes, I've been updated my latest version of fileupload.js here https://gist.github.com/simone83/5728231

                          Now it's work correctly even if you enable immediateUpload=true inside <rich:fileUpload>

                          (I've just pushedout the if-block:

                           

                                          if (this.immediateUpload) {

                                                   this.__startUpload();

                                          }


                          outside the loop for, as it had to be done).


                          I've also replaced all <tab> characters with a cleanest and fully supported simple <white space>'s ok?

                           

                          Have a nice day.


                          Simone.

                           

                          PS: succesfully tested with:

                                    - application server : JBoss AS 7.0, EAP 6.1

                                    - browser : IE 7, Firefox 14.0.1, Firefox 17.1

                           

                          PS2: Only one little issue still remains: with the maxFilesQuantity attribute of <rich:fileUpload> what can we do?

                                  The maxFilesQuantity property is working now but at a per-upload-request level, so for example let maxFileQuantity = N, if you choose K files (K > N)

                                  all K files will be uploaded, and only after the upload request has committed the framework receipts that the number of uploaded files greater than N

                                  then hides the "Add" button, correctly as specified in Component Reference here:

                                  http://docs.jboss.org/richfaces/latest_4_3_X/Component_Reference/en-US/html_single/#sect-Component_Reference-Rich_inputs-richfileUpload .

                           

                                  So if you and all the community agrees we have to think a new logic of behaviour for that:

                           

                                  in case of a multiple upload, when the maxFilesQuantity attribute of <rich:fileUpload> is set to N

                                  and we are uploading K files (where K>N), it will silently discards and skip the (K-N) files? Or it will send an error message, rejecting the upload request because the number

                                  of files is greater than the maxFileQuantity?

                                  --> I think the best solution is first (silently discard policy) and it requires minimal changes/efforts inside the fileupload.js (I've the new code ready if u agree).

                           

                          I don't know how to proceed about that if we need to open a new issue and close the RF-12224 or continue with development within the same issue,

                          so I still wait for your and community suggestions...

                           

                          However, if I'm not going wrong, I have to change the state to Resolved of this Jira RF-12224 assigned to me, when all the work is done correctly for me and the tests are ok. Right?


                           


                          • 25. Re: workaround for multipleUpload capability in <rich:fileUpload>
                            lfryc

                            The code should immediately after the loop check what is current total item count and compare it with maxFilesQuantity. In fact it should be probably compared inside the loop, read bellow.

                             

                            It can accept first N files from the K (in the order of for cycle) into the file upload (just for user's convenience - he doesn't want to choose K files and then suddently see that none of them were accepted).

                            However rest will be rejected with an error that will report e.g. "Only N files is allowed to be uploaded, but you have requested an upload of K files."

                             

                            ----

                             

                            Anoither question is whether HTML5 multi-file upload doesn't allow to set such kind of limits.

                             

                            Could you possibly investigate if we can limit the number of files / file types which user can choose?

                            • 26. Re: workaround for multipleUpload capability in <rich:fileUpload>
                              lfryc

                              Btw great job with checking all the consequences of setting other attributes!

                              • 27. Re: workaround for multipleUpload capability in <rich:fileUpload>
                                simone.83

                                >>The code should immediately after the loop check what is current total item count and compare it with maxFilesQuantity. In fact it should be probably compared inside the loop, read bellow.

                                >>It can accept first N files from the K (in the order of for cycle) into the file upload (just for user's convenience - he doesn't want to choose K files and then suddently see that none of them were accepted).

                                >>However rest will be rejected with an error that will report e.g. "Only N files is allowed to be uploaded, but you have requested an upload of K files."

                                 

                                Yes it's right. I've done tests yesterday with a new version of fileupload.js (not yet synchronized with online gists)  wich it breaks the for loop if length var is greather than of maxFilesQuantity,

                                (first of entering in loop I'll assign to length the value maxFilesQuantity if and only if:

                                 

                                          1) we are in multi-upload mode   

                                 

                                             AND   

                                 

                                          2) length is greatest than of maxFilesQuantity

                                 

                                ).

                                 

                                          .... It works!

                                 

                                But (umph!) :

                                 

                                    PROBLEM: If you upload K files and N of them are of an unsupported type you will get exactly N alert dialogs (so N onttyperejected events fired).

                                 

                                    SOLUTION: I can (if you agree) modify fileupload.js so it will  richfaces.Event.fire(this.element, "ontyperejected", fileName) only once at end of upload.

                                    So if there was files rejected, it will report only once at the end of upload completion. In fileName variable I can append all the rejected fileNames separeted by a comma ",".

                                    I think this is the simplest and minimal-effort solution and makes the things works.

                                 

                                    SOLUTION(2):we can do the same as for PrimeFaces implementation of multiple file upload in the showcase: http://www.primefaces.org/showcase/ui/fileUploadMultiple.jsf

                                    it will put a message into the upload history for any rejected file.   

                                 

                                 

                                 

                                 

                                >>However rest will be rejected with an error that will report e.g. "Only N files is allowed to be uploaded, but you have requested an upload of K files."  

                                 

                                    I'm an idea for that, but what kind of event I will fire? Or I need to create a new event like "onlimitexceeded" for example, and then fire it with richfaces.Event.fire(this.element, "onlimitexceeded")

                                    so the users can then show custom messages?

                                 

                                 

                                >>Could you possibly investigate if we can limit the number of files / file types which user can choose?

                                 

                                   Sure I can...I'm already onto w3c pages...

                                   ---> it seems there are no attributes for doing that at HTML5 component level, so the only way seems to be use the length property of array 'files'...

                                         ...but you can specify a list of mime types:  http://www.w3.org/TR/html-markup/input.file.html

                                • 28. Re: workaround for multipleUpload capability in <rich:fileUpload>
                                  lfryc

                                  Yeah, I think onfilerejected should be fired exactly once with all the files as a comma-separated string - it will preserve backward compatibility.

                                   

                                  +1 onlimitexceeded - again, it should report with a comma-separated list of files

                                   

                                  However I can see an inconsistency here - on an online demo [1], we can see that fileUpload doesn't report that file size was exceeded until a transfer starts.

                                  To be consistent here, we could use 'files' list and report directly (as you said, the same as PF do).

                                  However this suggestion is not consistent with a reporting of onfilerejected.

                                   

                                  I think we should address this in the future and make it consistent - for a sake of backwards compatibility for current users, I would adopt an solution which will be expected as of current behavior:

                                   

                                  - onfilerejected -> with comma separated list of files

                                  - whe limit exceeded - show a failure message

                                   

                                  mime-type cannot be implemented consistently as well, since RichFaces rather depends on

                                   

                                  I would report these requests for improvements for RichFaces 5:

                                   

                                  - support mime-types

                                  - onfilerejected/onsizeexceeded with array of files as parameter

                                  - duplicated with ability to show files in a file list with a message explaining why they can't be uploaded

                                   

                                  WDYT?

                                   

                                  [1] http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=fileUpload&skin=blueSky

                                  • 29. Re: workaround for multipleUpload capability in <rich:fileUpload>
                                    simone.83

                                    Surely, I agree...in this version we need to mantain the backward compatibility and too many changes/restructurations are needed for supporting multiupload as best...so it's better to do that in newest release of RF5.

                                     

                                    Now I'm working to the new version of fileupload.js for the onfilerejected issue.

                                    I've a question: on the RF 4.3.2 when onfilerejected event is fired, the user inside the <rich:fileUpload> tag specifies a javascript action to do (like alert('you can only upload JPG,BMP, GIF files');),

                                    but how the user can get the filename and then show in the alert for example?

                                     

                                    the call to:

                                     

                                    richfaces.Event.fire(this.element, "ontyperejected", fileName)


                                    contains the fileName variable, but I can't reach how this variable is then managed inside the framework, and how the

                                    user can get that...any suggestions?