how to generate "Image Not found Exception"

4 views
Skip to first unread message

Amith

unread,
Feb 20, 2007, 12:03:11 AM2/20/07
to Google Web Toolkit
Consider "http:\\testUrl.com\testImage.gif" is not present
and when i create an Image obj pointing the above url.. i.e

Image imgObj = new Image ("http:\\testUrl.com\testImage.gif");

it doesnt throw me any exception... What i want to do is, i will try
to get the testImage.gif.. if itz not present i want to display a
default image.. hw can i do it

Thanks in Advance
Amith

Adam T

unread,
Feb 20, 2007, 1:15:52 AM2/20/07
to Google Web Toolkit
Amith,

You should add a LoadListener to your image and handle the problem in
the onError part. For example:

Image imgObj = new Image ("http:\\testUrl.com\testImage.gif");

imgObj .addLoadListener(new LoadListener(){
public void onError(Widget sender) {
//Window.alert("Expected Error Showing That the onError() Method in
LoadListener works.");
}
public void onLoad(Widget sender) {
//Window.setTitle("Loaded Image: "+imageName);
}
});

You have to make sure that imgObj is added to the DOM though before
trying to load otherwise the onLoad event isnt handled - if you don't
want the image to be visibile when loading, just try
imgObj.setVisible(false)

Hope that helps!

//Adam
Co-author of GWT In Action http://www.manning.com/hanson

Amith

unread,
Feb 20, 2007, 1:55:03 AM2/20/07
to Google Web Toolkit
thnks a lot Adam, i will try it soon and reply u back...

Amith

unread,
Feb 20, 2007, 6:13:47 AM2/20/07
to Google Web Toolkit
Hw do i add imgObj to DOM? onLoad event is nt handled .. :(

Adam T

unread,
Feb 20, 2007, 7:23:32 AM2/20/07
to Google Web Toolkit
Essentially, you need to add your image into the DOM structure
displayed on the screen. The most brutish way is to shove it straight
to the screen, e.g. RootPanel.get().add(imgObj); but then you have
limited control as to where it is displayed and what you can do with
it.

More elegantly, and probably what you are already doing, is to put the
Image object in another Panel of some kind. That Panel itself needs
to be added to the DOM structure either by adding it to other Panels,
or using RootPanel.get().add(the panel) or RootPanel.get(name of
slot).add(the panel).

Only once there is a chain from RootPanel to your image will the load
listener get events (since events start in the DOM and then GWT moves
them through widgets/panels that are attached).

If it still doesn't work, feel free to mail me direct using the
address in my profile.

//Adam
Co-author of GWT In Action http://www.manning.com/hanson

Amith

unread,
Feb 20, 2007, 8:40:26 AM2/20/07
to Google Web Toolkit
thnks a lot Adam...

RootPanel.get().add(imgObj);
this is what i was looking for.. thats enf for me..
it works....

do chk www.spotDue.com/beta in ur free time and tell me hw can i
improve it...

thnks again
Amith GC

Reply all
Reply to author
Forward
0 new messages