java - How to check if image file exists in classpath through gwt client side? -
i creating image
object want set url of image dynamically.
image img = new image(); if(vehicletype.equals("car")) img.seturl(images/car.png); else img.seturl("");
here, don't know if car.png
exists in images folder in classpath. how can check existence? want set default vehicle image object if car.png
not on classpath.
thanks
you can't check if image on class path client side.
what can add errorhandler
image
adderrorhandler()
method can detect if browser can't load image (because doesn't exist on server side example).
image img = new image(); img.seturl("set url"); img.adderrorhandler(new errorhandler() { @override public void onerror(errorevent e){ // failed load image } });
note: there image.addloadhandler()
method can use detect when image loaded.
another way create method @ server side published in service checks if image availabe, , call method client code.
a side note
if you're 1 writes client code , tell image url images/car.png
, you're 1 assembles server side resources, shoudln't happen. @ production environment shouldn't use such checks. if somewhere write img.seturl("images/car.png")
should make car.png
available @ server side , not bother such runtime client side checks.
Comments
Post a Comment