Image not showed in a Form

Hi:

I started to play with SOM… unsuccessfully :(

I want to show images in a Dialog Window, but their size are different, so I’m going to create (via SOM) a form and put this form in a dialog with the size of the image. First, I get the image size:

plugins.http.createHttpClient('HTTPCLIENT');
var imgFile = plugins.http.getMediaData(url_to_image, 'HTTPCLIENT');
var img = plugins.images.getImage(imgFile);

Then, I create the form (without navigator):

var f = solutionModel.newForm('det_img', controller.getServerName(), controller.getTableName(), my_style', false, img.getWidth(), img.getHeight());
f.navigator = SM_DEFAULTS.NONE;

Now, I create a field where to put the image:

f.newImageMedia(img, 0, 0, img.getWidth(), img.getHeight());

And finally I show the form in a dialog:

application.showFormInDialog('det_img', -1, -1, img.getWidth(), img.getHeight(, 'Detalle Imagen', false, false);

But the image doesn’t show… What’s wrong??

Thanks

Log-out,

The first to f.newImageMedia() is the dataProvider, not the image data.
Try storing the data in a global and use the gklobal name in f.newImageMedia().

Rob

I’ve tried this (using a form variable):

var fv = f.newFormVariable('fld_img_g', SM_VARIABLETYPE.MEDIA);
fv.defaultValue = img;
f.newImageMedia('fld_img_g', 0, 0, img.getWidth(), img.getHeight());

But it doesn’t work :cry:

log-out:
I’ve tried this (using a form variable):

var fv = f.newFormVariable('fld_img_g', SM_VARIABLETYPE.MEDIA);

fv.defaultValue = img;
f.newImageMedia(‘fld_img_g’, 0, 0, img.getWidth(), img.getHeight());




But it doesn't work <img src="{SMILIES_PATH}/icon_cry.gif" alt=":cry:" title="Crying or Very sad" />

If your global is indeed called fld_img_g, try using:

f.newImageMedia('globals.fld_img_g', 0, 0, img.getWidth(), img.getHeight());

If your global is indeed called fld_img_g, try using:

f.newImageMedia('globals.fld_img_g', 0, 0, img.getWidth(), img.getHeight());

It’s not a global, it’s a form variable (using newFormVariable())

Yes, you are right, sorry.
But maybe this form variable is not properly initialized at the time you assign it to the field.

Does it work if you use a global?

ptalbot:
Does it work if you use a global?

Yes, it works… But i’d prefer not to create a global for it. So doesn’t newFormVariable() work correctly?

Apparently not as it should be ;-)

I would submit a case to the support system if I were you.

I had a similar issues in Servoy 4. Form variables did not display in labels, while global variables (same type, same value) displayed correctly. http://forum.servoy.com/viewtopic.php?f=8&t=10936

Hello all

We have also faced this problem.
The problem is the new form variable is not getting initialized. Which results in not showing the image in the image media field.
What you can do, create media type variable(s), dont need to initialize(since it doesnot work), create newimageMedia(s) by using this newly created variable.
Now the show the form.
After displaying the form, use this

forms[formName].controller.setDataProviderValue(variableName, imageData)

Here, formNamme : newly created form name, in your case ‘det_img’
variableName : the dataprovider/ variable name which is attached to the image media
imageData : byte of the image

This will modify the dataprovider(s).

Hope this will work.

log-out:
I’ve tried this (using a form variable):

var fv = f.newFormVariable('fld_img_g', SM_VARIABLETYPE.MEDIA);

fv.defaultValue = img;
f.newImageMedia(‘fld_img_g’, 0, 0, img.getWidth(), img.getHeight());

Log-out,

You are trying to mix solution model with runtime form objects.

Note that when you are setting the defaultValue property of a JSVariable, you are working in the solution model, the variable has not been instatiated (created) yet.
This is equivalent to typing “var fld_img_g = ‘somedefault’” in the javascript form editor.

In the solution model you can only use strings for default value (same as that you can only type strings is in the js editor)

pradiptab’s approach is correct.
The variable is ‘designed’ first with the solution model (create variable and field).
And after instantiating the form, the variable actually exists and can be assigned a media value.

Rob