0

problem in refreshing image

asked 2008-09-23 21:32:39 +0800

siamakh gravatar image siamakh
39

Hi,
I am having a problem in refreshing images. Please check the zul below. The zul displays "images/me.jpg", I want to be able to refresh the image after the images/me.jpg is replaced with another image with same name and path on the server. But refreshing does not work. Please try the below zul, replace me.jpg with another image with same name and click on refresh. The image wont be refreshed on browser unless i refresh the page. Is there a way around this?

<?xml version="1.0" encoding="UTF-8"?>
<?page title="MV Admin" cacheable="false"?>

<window>
<image id="myImage"/>
<button label="refresh" onClick="refreshImage()"/>
<zscript>
imageName = "images/me.jpg";
refreshImage()
{
myImage.setSrc(imageName);
//i have also tried invalidate and re-attaching myImage but none seems to work
}

refreshImage();
</zscript>
</window>

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2008-09-24 06:05:50 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

Set the same value to a attribute will not cause any update.
Could you try myImage.invalidate() instead of myImage.setSrc

link publish delete flag offensive edit

answered 2008-09-24 16:29:28 +0800

siamakh gravatar image siamakh
39

Thanks for your reply dennis. I have tried invalidate too (its there in my comments). Here you can use the below sample which detaches, recreates and invalidates the Image but still does not refresh the image:

<?xml version="1.0" encoding="UTF-8"?>
<?page title="MV Admin" cacheable="false"?>

<window id="win">
<button label="refresh" onClick="refreshImage()"/>
<image id="myImage"/>
<zscript>
imageName = "images/me.jpg";
refreshImage()
{
myImage = win.getFellow("myImage");
myImage.detach();
myImage = new Image();
myImage.setSrc(imageName);
myImage.setId("myImage");
myImage.invalidate();
myImage.setParent(win);
}

refreshImage();
</zscript>
</window>

link publish delete flag offensive edit

answered 2008-09-25 00:17:54 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

The browser cache the image locally. A common work around is to append "?RANDOMNUMBER" after the imageName so breaks the cache.

link publish delete flag offensive edit

answered 2008-09-26 23:49:31 +0800

siamakh gravatar image siamakh
39

thanks! that was it.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-09-23 21:32:39 +0800

Seen: 217 times

Last updated: Sep 26 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More