Loading Image in Java using org.zkoss.zul.Image.setSrc

asked 2008-09-26 15:20:33 +0800

ansancle gravatar image ansancle
317 9

I am trying to set the contents of an image using org.zkoss.zul.Image::setSrc in my Java code. Every possible permutation of the path to the image file has failed to load the image.

Just to be sure, I added the following into my .zul file and the image showed right up.

<image src="/stylesheets/images/zones/speakers_32x32.png"/> 

Can someone please help me figure out how to load an image from the filesystem in the java code using a path. I even wrote a small app that allowed me to try paths by entering them into a page and it would update the image using setSrc and the path, everything I tried failed including the full path with http:// etc....

Im sure this is simple but my searches failed to produce an answer,


delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-09-29 07:17:26 +0800

dennis gravatar image dennis
3669 1 6

ZK add "Application Context" to src if the attribute start with "/" , it is very common usage in J2EE.
form the view of HTML , it will become <IMAGE src="/APP_CONCTXT/stylesheets/images/zones/speakers_32x32.png" />

The image file in file system should be pleased at file:YOU_APPLICATION_FOLDER/stylesheets/images/zones/speakers_32x32.png

link publish delete flag offensive edit

answered 2008-09-30 13:21:49 +0800

ansancle gravatar image ansancle
317 9

Figured it out, so I might as well post it for somebody else to see if need be.

I already new that the path to the image needs to be from the root, but my mistake was in not just setting the path into the setSrc method on button but instead creating an image, setting the src on that, then using the Button.setImageContent(Image.getImageContent());

For example :
In my application WEB-ROOT/zul is the root, my images are under WEB-ROOT/zul/stylesheets/images, so the path that you set into the setSrc method on Button is /stylesheets/images/imageName.png, etc....
The second part of this is I was initially creating an Image, setting the src on the Image, then using that Image to call Button.setImageContent(Image.getImageContent()) - This didn't work.
Just using the correct path to the image and calling setSrc on the Button works.

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




Asked: 2008-09-26 15:20:33 +0800

Seen: 797 times

Last updated: Sep 30 '08

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