-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I'm trying to display an image from a database in a web browser from java code. I've followed lot of examples and din't succced.
One of the examples I tryied loks like folows (I've supressed some non relevant code).
public class AlbumViewCtrl extends SelectorComposer<Window> { @Wire private Image mainImage; @Wire private Textbox imgText; @Listen("onClick=#addwBtn") public void uploadImage() { File file = new File("/home/ntsetso/icons/trashcan.ico"); byte[] bFile = new byte[(int) file.length()]; try { FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.read(bFile); fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } this.novoAlbum.setFoto(bFile); this.novoAlbum.setNome("trashcan.ico"); albumDao.insert(this.novoAlbum); } @Listen("onClick=#showBtn") public void displayImage() { Album album = albumDao.findLine(imgText.getValue()); InputStream fileData = new ByteArrayInputStream(album.getFoto()); mainImage.setContent(new AImage("trashcan.ico", fileData)); } }
The last line is where I can't go further as I receive the warning: "The method setContent(AImage) is undefined for the type Image".
Any explanation will be appreciated.
rgrds.
ntsetso
One more Question:
Bellow is a modified code from Zk Sandbox, Multimedia and Utilities, Fileupload.
<zk> <button label="Upload" upload="true"> <attribute name="onUpload"> { org.zkoss.util.media.Media media = event.getMedia(); if (media instanceof org.zkoss.image.Image) { pics.setContent(media); } else { Messagebox.show("Not an image: " + media, "Error", Messagebox.OK, Messagebox.ERROR); break; //not to show too many errors } }</attribute> </button> <vbox> <image id="pics" /> </vbox> </zk>
On eclipse I get two warnings: "The method getMedia() is undefined for the type Event" and "The method setContent(Image) in the type Image is not applicable for the arguments (Media)", but it works anyway.
The original code gives the same warnings as well. Is there some thing missing?
In zscript, types are not strictly checked. You would have encountered a compile error if the same code is in a java class. Nonetheless, your runtime types are correct, thus it runs fine. So the answer is: Nothing is missing or wrong.
May this example help you ?
Please through this http://javaj2eehub.com/zk-setcontent-to-an-image-component/ may it helps u
Asked: 2012-07-24 14:13:10 +0800
Seen: 394 times
Last updated: Jul 02 '13