views:

41

answers:

2

Hi, has anyone encountered a problem where you register a LoadHandler on the image, and when the image is loaded the LoadHandler doesn't get called sometimes? Is there some voodoo to make it work? Like some ridiculous order of initialization? This is driving me nuts.

The code works on Firefox, Chrome, IE6 and IE7. The image is attached to the DOM (I know LoadHandler won't get called if the image is not attached).

Edit

I have reduce the larger code to the following snippet.

private void loadNext() {
    if (count < urlList.size())
        Image displayImage = new Image();
        displayImage.addLoadHandler(new ImageLoadHandler());
        displayImage.addErrorHandler(new ImageLoadError());
        mainPanel.add(displayImage);
        displayImage.setUrl(urlList.get(count));
        return;
    }
}

private class ImageLoadHandler implements LoadHandler {
    public void onLoad(LoadEvent event) {
        count ++;
        Log.TRACE("Success");
        loadNext();
    }
}

private class ImageLoadError implements ErrorHandler {
    public void onError(ErrorEvent event) {
        Log.ALERT("Error");
    }
}

So basically this loads images one by one once the previous one has finished loading. The problem that occurs is the first image shows up as red x in IE8 and an error is caught. Now, if I right click on the image and click "show picture" it shows up, and triggers something such that the onLoad event is fired and the rest of the images load without errors! Now all of a sudden onLoad event works, all the other images which are same type are no longer an error.

the urlList is a list of urls to the images. The URL does not contain an extension for image type. The URLs go to a servlet which generate an image. I have taken care to set the proper Content-type headers (image/jpeg) in the response.

Furthermore, if I right click on the broken image, IE8 shows that it doesn't know its type. If I copy the URL, paste it in the address bar, IE loads the image just fine on its own. Now it seems to know the type when it's not in tags.

Very frustrating.

Thanks.

+2  A: 

Hi

I encountered the same problem, after several days of inspection we found that it is internal bug of IE8 with its image cache. Try to delete complete browser history if it works for the first time. If it is your case then working solution is to add dummyParam to every image URL (with value e.g. new Date().timeInMilis() or something similar). I made this param enabled for user.agent=ie8 only.

I am really afraid of IE9 :(.

Marek Gregor
I will try that. Thanks.
Budric
A: 

It turned out that this is a known GWT Bug.

Updating to GWT 2.1 should solve the problem.

adranale