-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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,
Thanks
Andrew
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
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.
Asked: 2008-09-26 15:20:33 +0800
Seen: 806 times
Last updated: Sep 30 '08