Unload changes the form structure

Hi guys,

This is my first time seeing Unload() event in action and it’s doing something not quite expected.
My solution has multiple windows and every window is made of clones of the original window. Literally each form is a solutionModel clone, because I need to show the same window on the screen more than once at any particular time.

The problem appears when I open more than three or four windows and ‘pre-load’ a couple of them in memory without showing them to the user. Servoy starts its own memory management and unloads some forms, that are not currently on the screen.

Now, when I bring those forms up on the screen, Servoy loads them back, however they have original tab forms links.
I’ll explain.
When I clone a window, I also clone all forms on its tabpanels.
After the cloning has finished, I load the forms (just calling forms[formName]) and then remove all original tabs and replace them with the cloned tabs.
So, if I had form ‘job’ that contained a tabpanel with form ‘job_details’ (that’s stage 1), after cloning (stage 2) it will be ‘job_clone’ containing ‘job_details’ and after loading form ‘job_clone’ (stage 3) it will be ‘job_clone’ containing ‘job_detail_clone’. Tabs are removed with .removeAllTabs() and put back with .addTab(), so it’s not solutionModel changes.

Everything is fine till the point when Servoy unloads some forms, like ‘job_clone’.
When it brings it back and reloads it, the form is back to stage 2: form ‘job_clone’ has tab ‘job_detail’ instead of ‘job_detail_clone’. Obviously it ruins a lot of things, as I rely on a particular form being in a particular tab.

I would like to know if that is what is supposed to happen or it’s a bug, it doesn’t sound right.

Also, I’d like to know how to deal with it. I assume I’ll be advised to replace tabs at the cloning stage with solutionModel, but that is how it used to be and we refused that method for a few reasons.

Thanks for your feedback, looking forward to a discussion.

maria.kyselova:
I would like to know if that is what is supposed to happen or it’s a bug, it doesn’t sound right.

At unload, the form is removed from the Servoy cache.
So next time it is loaded again, Servoy will load the form from it’s blueprint (the designtime forms)
For your cloned forms these are the forms as you cloned them using the solutionModel.
Any changes you did at runtime will NOT be stageful (but I consider this to be common knowledge to any Servoy developer)
As you didn’t change the default tabpanels using the solutionModel (making it designtime properties), the tabpanels will be the original ones.
So the behaviour you see is 100% expected.

maria.kyselova:
Also, I’d like to know how to deal with it. I assume I’ll be advised to replace tabs at the cloning stage with solutionModel, but that is how it used to be and we refused that method for a few reasons.

Somehow you already know the nr.1 answer: use the solutionModel to assign the new tabpanels.
An alternative could be: assign a ‘onLoad’ method to the cloned form which will handle the setup of the tabpanels for you.
To be able to do this you should keep a reference somewhere that knows what the ‘cloned tabpanel’ is for a particular tabpanel in a particular cloned form.

It’s either one of these options, but I think from my answer you can already tell what I’d prefer… :-)

mboegem:

maria.kyselova:
I would like to know if that is what is supposed to happen or it’s a bug, it doesn’t sound right.

At unload, the form is removed from the Servoy cache.
So next time it is loaded again, Servoy will load the form from it’s blueprint (the designtime forms)
For your cloned forms these are the forms as you cloned them using the solutionModel.
Any changes you did at runtime will NOT be stageful (but I consider this to be common knowledge to any Servoy developer)
As you didn’t change the default tabpanels using the solutionModel (making it designtime properties), the tabpanels will be the original ones.
So the behaviour you see is 100% expected.

maria.kyselova:
Also, I’d like to know how to deal with it. I assume I’ll be advised to replace tabs at the cloning stage with solutionModel, but that is how it used to be and we refused that method for a few reasons.

Somehow you already know the nr.1 answer: use the solutionModel to assign the new tabpanels.
An alternative could be: assign a ‘onLoad’ method to the cloned form which will handle the setup of the tabpanels for you.
To be able to do this you should keep a reference somewhere that knows what the ‘cloned tabpanel’ is for a particular tabpanel in a particular cloned form.

It’s either one of these options, but I think from my answer you can already tell what I’d prefer… :-)

Thanks Marc.
I figured that would be the answer :) But thanks for the confirmation.
Like I said, the first method will not work for what I want to do, but I’ll try the second approach (I have a naming convention in place, so knowing which tabpanel should be where is not a problem).

Yep, that worked, Marc. Thanks mate.

Nice :-)
B.T.W.: you mentioned cloning the forms. Why don’t you use form extension? That way you don’t need a full copy and it still behaves the same as your parent form.
Difference here is that it’s a more lightweight solution. As the extended forms are running in their own scope, you still have the possibility to change your forms individually.

mboegem:
Nice :-)
B.T.W.: you mentioned cloning the forms. Why don’t you use form extension? That way you don’t need a full copy and it still behaves the same as your parent form.
Difference here is that it’s a more lightweight solution. As the extended forms are running in their own scope, you still have the possibility to change your forms individually.

Let me process it, Marc. That would be a revelation!

mboegem:
Nice :-)
B.T.W.: you mentioned cloning the forms. Why don’t you use form extension? That way you don’t need a full copy and it still behaves the same as your parent form.
Difference here is that it’s a more lightweight solution. As the extended forms are running in their own scope, you still have the possibility to change your forms individually.

Well, I created a sample solution and it broke from the very beginning.
I have a main form with a button ‘Open’ that opens a new window.
The new window is made with solutionModel: solutionModel.newForm(name, solutionModel.getForm(‘baseForm’)); - so it extends the base form.

It’s all good as long as ‘baseForm’ has no tabpanels.
If I put a tabpanel on baseForm and open more than one window, the tabpanel is only enabled and visible in the last window that I opened. I understand it’s because one can’t show the same form more than once on the screen, old rule.

So even if the main form is extended, the tabs are not. Should they be? Am I doing it wrong?
Sample solution attached.

testExtendedForms.servoy (4.52 KB)

maria.kyselova:
So even if the main form is extended, the tabs are not. Should they be? Am I doing it wrong?

Like you wrote: same old rules.
It’s not a magic function that drops all we’ve learned before.

Currently you’re cloning main form as well as all the tab forms.
That doesn’t change when using form-extension.
The only thing I pitched to you was to use extension instead of cloning, because it’s a more lightweight solution.
All your other code remains the same.

Hi,

when I do this

var $name, $form, $newForm, $win;
$name = '_'+new Date().getSeconds()
$form = solutionModel.getForm('_test');
$newForm	= solutionModel.newForm($name, $form);
$newForm.namedFoundSet	= JSForm.SEPARATE_FOUNDSET; 
	
$win	= application.createWindow($name, JSWindow.WINDOW);
$win.show($name);

I can open the base form as many times as I like

[attachment=0]2014-12-02_0817.png[/attachment]

Regards,

Peter

Peter de Groot:
Hi,

when I do this

var $name, $form, $newForm, $win;

$name = ‘_’+new Date().getSeconds()
$form = solutionModel.getForm(‘_test’);
$newForm = solutionModel.newForm($name, $form);
$newForm.namedFoundSet = JSForm.SEPARATE_FOUNDSET;

$win = application.createWindow($name, JSWindow.WINDOW);
$win.show($name);




I can open the base form as many times as I like

[attachment=0]2014-12-02_0817.png[/attachment]

Regards,

Peter

I know right!
I can’t use separate foundset though, all of my forms are related to each other.