Wednesday, November 27, 2013

Re: GWT FileUpload with Progress Listener

Hi Jens, 

thanks for your help. I know the concept but did not fully understand you. 

1. What do you mean by: "Don't forget to cleanup the event listener after you are done."?

2. Did I get you right on the following. Since I use the progress for file upload I have to use a FormPanel. 

my progress listener class would be like: 

class MyProgressListener {
      void onProgress(int loaded, int total) {
         // so something with the data

then I would do something like: 

final FormPanel form = new FormPanel();

    VerticalPanel panel = new VerticalPanel();

FileUpload upload = new FileUpload();

// Add a 'submit' button.
    panel.add(new Button("Submit", new ClickHandler() {
      public void onClick(ClickEvent event) {

3. How do I integrate the setProgressListener method in the FormPanel?

Thanks for help.

Am Mittwoch, 27. November 2013 16:51:45 UTC+1 schrieb Jens:
Well if you already know the concept of JSNI then you can use it to add a listener to GWT's XMLHttpRequest as its an ordinary JavaScriptObject. You either extend it or create a utility method. Something along these lines (probably not fully correct):

public native void setProgressListener(MyProgressListener p) /*-{
  this.upload.addEventListener("progress", function(event) {
  }, false);

A utility method would have an additional XMLHttpRequest parameter and use request.upload instead of this.upload.

Don't forget to cleanup the event listener after you are done. Also note that XMLHttpRequest.create() can return an IE specific object which might not support the progress feature or which requires you do register the listener differently. So your implementation might be a bit more complicated depending on your browser support requirements.

-- J.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment