Is the imageURL property still available in Servoy 6?

Hi everyone,

There seems to be some confusion with the “imageURL” property of labels. Servoy Version: 6.0.6 - build 1232 says the “imageURL” property does not exists.

However, this topic from a year ago recommends using the “imageURL” property of labels:
viewtopic.php?f=22&t=16685

And the current documentation for JSLabel does not list the “imageURL” property:
http://wiki.servoy.com/display/public/DOCS/JSLabel

All I want to do is attach an image based on the URL like so (taken from the forum post above):

elements.label.imageURL = "media:///image.png";

The method below seems to be the only option left in the current version of Servoy, but I’d prefer not to use it because the image loaded could be a jpeg, gif or png and I’m not sure if this would cause errors:

/** @type {JSLabel}*/
var imgLabel = myForm.newLabel("Image Here",20,20,100,100);
var imgBytes = plugins.file.readFile("media:///image.png");
var imgImage = solutionModel.newMedia("image.png", imgBytes);
imgLabel.label.imageMedia = mapImage;

Of course I could splice out the filename from the URL and re-use it in the “newMedia()” call, but this seems to be an awfully cumbersome solutions when the “imageURL” property managed to do it in one line.

Thanks for any advice on this.

Micah

Where did you get the message that the property doesn’t exist? Because it is still there in 6.0.6, I use it a lot :).

If you are doing elements.label, you are talking to a RuntimeLabel, which is NOT a JSLabel. A RuntimeLabel is an object from the runtime api, and a JSLabel is an object from the designtime api (the solutionModel).
Here a list of the properties of a RuntimeLabel: http://wiki.servoy.com/display/public/DOCS/RuntimeLabel

Thanks for the quick reply Joas,

Indeed, this is a solutionModel label and not a runtime model label. I see the difference between the two now. So am I right in assuming that the code below is the only way to dynamically create a Label and attach an image to it? In the example below I am loading the image URL as a String from the database.

	/** @type {JSLabel}*/
	var imgLabel = myForm.newLabel("Image Here",20,20,100,100);

	if(foundset.img_url != null){

		//Get the filename from the URL to use in newMedia()
		var imgFilename = foundset.image_url.substring(foundset.image_url.lastIndexOf('/')+1);
		
		//Read the file based on the URL from the database into a byteArray
		var imageBytes = plugins.file.readFile(foundset.image_url);

		//Create a JSMedia object from the byteArray
		var imgImage = solutionModel.newMedia(imgFilename, imageBytes);

		//Show the JSMedia object in the label
		imgLabel.imageMedia = imgImage;
	}

Although this seems like a plausible approach to me, I am getting this error (the filename of the image being image.gif):

The name 'image.gif' already exists as media
Wrapped java.lang.RuntimeException: error createing new media with name image.gif

All I am trying to do is to display an image on a form generated using the solutionModel, based on a URL from the database. So If I am completely off-track here, please let me know.

I appreciate all the help,

Micah

I think I’ve found a decent solution. Deriving the file name was of course not necessary for the name of the image. I only had to make sure to remove any Media Object with the same name when I want to swap the image.

My code below. If there is a simpler solution, any advice is welcome:

	/** @type {JSLabel}*/
	var imgLabel = myForm.newLabel("Image Here",20,20,100,100);
	
	if(foundset.img_url != null){
		solutionModel.removeMedia('imgName');
		var imgBytes = plugins.file.readFile(foundset.img_url);
		var imgImage = solutionModel.newMedia('imgName', imgBytes);
		imgLabel.imageMedia = imgImage;
	}

Thanks again,

Micah