0

How to setContent to an Image component?

asked 2012-07-24 14:13:10 +0800

ntsetso gravatar image ntsetso
59 1 4

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

delete flag offensive retag edit

10 Replies

Sort by ยป oldest newest

answered 2012-07-24 18:05:05 +0800

jj gravatar image jj
638 3

Maybe your mainImage is not the correct type? Check if it is org.zkoss.zul.Image

link publish delete flag offensive edit

answered 2012-07-24 18:41:55 +0800

ntsetso gravatar image ntsetso
59 1 4

I was using "org.zkoss.image.Image" instead of "org.zkoss.zul.Image".

thanks a lot.

link publish delete flag offensive edit

answered 2012-07-26 02:14:37 +0800

ntsetso gravatar image ntsetso
59 1 4

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?

link publish delete flag offensive edit

answered 2012-07-26 02:54:50 +0800

jj gravatar image jj
638 3

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.

link publish delete flag offensive edit

answered 2012-07-26 03:38:42 +0800

ntsetso gravatar image ntsetso
59 1 4

Tks for explanation.
Just for the second warning I found it goes by casting:

pics.setContent((org.zkoss.image.Image) media);

link publish delete flag offensive edit

answered 2012-09-01 14:39:21 +0800

Fandogh gravatar image Fandogh
3

i have the same problem to !
it tells me that my media is not instanceof image ! i dont know why ! please help !

link publish delete flag offensive edit

answered 2012-09-02 14:13:13 +0800

ntsetso gravatar image ntsetso
59 1 4

It may help if you post your code.

rgrds.

link publish delete flag offensive edit

answered 2013-07-01 15:51:40 +0800

surendar gravatar image surendar
1

Hi,

"The method getMedia() is undefined for the type Event"

how did you overcome the above warning ?

link publish delete flag offensive edit

answered 2013-07-01 16:54:27 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

May this example help you ?

link publish delete flag offensive edit

answered 2013-07-02 16:54:03 +0800

jatindersingh gravatar image jatindersingh
93 5
http://javaj2eehub.com/

Please through this http://javaj2eehub.com/zk-setcontent-to-an-image-component/ may it helps u

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: 2012-07-24 14:13:10 +0800

Seen: 394 times

Last updated: Jul 02 '13

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