• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

apache.commons.fileupload - Browser blocks ajax requests

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I hope you can help me with my problem.
I want to have a progressbar at my page, which displays the status of a fileupload.

Therefore I got a <h:form>-tag like this :







When the user clicks the commandButton the upload is started. On the server side the send request is wrapped and the request is parsed by a ServletFileUpload object. This looks like this:






The installed ProgressListener just sets a sessionvariable called "FileUpload.Progress.finished" if the upload is ready. Furthermore the percentage of written bytes is stored in the session under the key "FileUpload.Progress.file" (You can't see it here, its done while writing the Fileitems to disk).



There is also registered a onclick listener to the button, which starts the polling. It is sending an ajax.request to render the progressbar.

The javascript looks like this :







Okay,we nearly got it : ) . Last there is the uploadBean.upload method :







This method gets invoked before the page gets rendered. Thats because i registered a preRenderView event listener to the page. This means, that this method gets called after every send ajax request, which goes through the partial lifecycle to render the progressbar. The method eventually adds new Bytes to the progressElements list. The list gets used by the ui:repeat element to build the progressbar. Finally the method checks if the FileUpload.Progress.finished attribute was set by the ProgressListener, which we installed to the ServletFileUpload instance (you remember ? ; ) ).

Ok, i hope you understood the set up. And now to my problem. When i upload a file, there are no ajax requests send, while uploading. The result is that my progressbar doesnt update itself.



Do you know a workaround, or at least can tell me the reason of this ?
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm sorry to say that I'm too busy to read through all of the stuff that you've gone to the trouble of
posting - however my experience has been that the tomahawk fileupload, and possibly anything in
a multipart form does not support ajax. The whole issue of uploading and downloading files has
been nothing but trouble from start to the present day. I now have a solution that allows file upload
via tomahawk fileupload and download via a servlet and h:graphicImage. I've adopted the "let's
just get the main job done and avoid any of the fancy stuff" approach and I'd suggest that you do
the same unless you have 2-3 months contingency built in to your project plan that you want to use
messing around with this stuff.

Brendan.
 
Tobias Guennewig
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brendan Healey wrote:
I'm sorry to say that I'm too busy to read through all of the stuff that you've gone to the trouble of
posting - however my experience has been that the tomahawk fileupload, and possibly anything in
a multipart form does not support ajax. The whole issue of uploading and downloading files has
been nothing but trouble from start to the present day. I now have a solution that allows file upload
via tomahawk fileupload and download via a servlet and h:graphicImage. I've adopted the "let's
just get the main job done and avoid any of the fancy stuff" approach and I'd suggest that you do
the same unless you have 2-3 months contingency built in to your project plan that you want to use
messing around with this stuff.

Brendan.



Hey, thanks four your reply.

I actually don't use the Tomahawk fileupload-tag, I'm using my own crafted staff. I did sum research and got stuck on the richfaces fileupload tag. It seems that this tag offers a progressbar. But I'm wondering how they made it work. I think i will try to integrate the richfaces tag into my project. But i realy would like to know, why my ajax polling doesn't work. The richfaces tag is also working with ajax, but their progressbar gets updated.

I think the problem is the parseRequest method of the ServletFileUpload instance in the constructor of the RequestWrapper. I think the control Thread remains in this method until all files were uploaded. And for some reason, the same client cant send any requests , while the other request isn't fulfilled.
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Http normally sends data as an atomic unit, which is why basic file upload progress bars don't work. They go from 0% ... long delay ... 100% with nothing in between.

Without actually checking, I think RichFaces is breaking the upload request into chunks so that it can monitor fractional progress.

I have used the RichFaces upload and it works well for me. Personally, I think it would be better to use the standardized off-the-shelf plugin solution (RichFaces) over spending a lot of time designing, debugging, and puzzling out quirks.
 
Tobias Guennewig
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Http normally sends data as an atomic unit, which is why basic file upload progress bars don't work. They go from 0% ... long delay ... 100% with nothing in between.

Without actually checking, I think RichFaces is breaking the upload request into chunks so that it can monitor fractional progress.

I have used the RichFaces upload and it works well for me. Personally, I think it would be better to use the standardized off-the-shelf plugin solution (RichFaces) over spending a lot of time designing, debugging, and puzzling out quirks.



Thanks for your reply. I already gone the RichFaces way. Besides I thank you for your explanation how richfaces may progress the upload, it drived me crazy not to know how they solved the problem ; )



 
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic