1

I want execute some logic after the moment when widget is attached and all images inside this widget are loaded. This widget show a block of html prepared in CMS (so the number of images is dynamic).

What have I tried:

  • override Widget.onAttach() or Widget.onLoad(). Unfortunately both of them are executed before the moment when all images are loaded.
  • I found gwt-image-loader library which can add a callback per image. I wan't use it due to dynamic nature of the content.

In JavaScript there is this option which works great:

$('selector').waitForImages(function() {
    // do some logic
});

Maybe I missed some GWT way to do the same thing?

Community
  • 1
  • 1
Maksym Demidas
  • 7,707
  • 1
  • 29
  • 36

2 Answers2

0

You can try GWT's Image.addLoadHandler()

Churro
  • 4,166
  • 3
  • 25
  • 26
  • Could you please provide more details about how I can use it in my situation? As I mentioned in the question I do not have a reference to any `Image` object. I only have a reference to parent `Widget` object. Thank you. – Maksym Demidas Aug 02 '13 at 08:39
  • My method does not work if you don't have an `Image` object. What kind of Widget is the parent Widget? A hacky option would be to use the jQuery `waitForImages()` function, and from there, [call your GWT code via JSNI](http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html). – Churro Aug 02 '13 at 21:09
  • It is `MCustomView extends Composite`. I am do not asking for hack because it was implemented already :-). – Maksym Demidas Aug 05 '13 at 08:33
0

onLoad and onAttach methods are there to inform you that the <img> tag is attached to your document and that is it. This helps in setting image attributes such as height, width, position and so on. What you are asking is, after the image is attached to document you want an handler after the image is rendered. This is not possible with the current version of GWT as per my experience. Further rendering of image depends on the network you are in, the server you are connected and so on. So instead of wanting for a render callback, try to do the work in onLoad or onAttach methods or add a loadHandler for the same

Abhijith Nagaraja
  • 3,370
  • 6
  • 27
  • 55