solutionModel.getForm(_form) returns null

Hi everybody,

I’m trying to use the solutionModel to create the desing of a form on the fly.
For what I’ve found, I need to remove the form from history and from the solutionModel.
The problem is that after that solutionModel.getForm(_form) does not find my form thus returning null.

Here is some of my code to change the form.

var form = solutionModel.getForm('presupuestos_aux')
	var success = history.removeForm('presupuestos_aux')
    if (success)
   	{
    	if(solutionModel.removeForm('presupuestos_aux'))
		{
                //Set a DataSource to the form
			form.dataSource = data.createDataSource('presupuestos',types)
			for(var h = 0; h < columns.length; h++)
			{
				var x, y, wth, hgh
				x = y = 0
				wth = 50
				hgh = 10
				var field = form.newField(columns[h], JSField.TEXT_FIELD, x, y, wth, hgh)
				field.name = columns[h]
				field.editable = true
				var label = form.newLabel(columns[h],x,y,wth,hgh)
				label.labelFor = columns[h]
			}
//Calls a method to change elements colors. Inside this method solutionModel.getForm('presupuestos_aux') is called and returns null		
			dc_edit(_event,_triggerForm)
		}
}

Am I missing something??

Thanks for the help.

Cheers

Hi,

What happens when you show the form before you trigger that method ?

nromeou,

After the solutionModel.removeForm() I see no solutionModel.newForm() call, where is the form design created again?

Rob

Hi,

Thanks for the answers.

Robert, do you mean before the code I posted or before dc_edit method??
If it is before the code I posted It wouldn’t make sense since the form is empty, and after I show it history.removeForm returns false so I can’t change anything with the solutionModel. If it is before dc_edit, the form appears empty as the original.

Rob, how do I make solutionModel.newForm take the JSForm object I already have??
Otherwise it’s no use to change a form if you have to create it from scrach later.

Thanks for the help

Cheers

Hi,

nromeou:
Robert, do you mean before the code I posted or before dc_edit method??

Before triggering the dc_edit method.

Hi,

Robert, it depends on the way I try to show it. If I do forms[_form].controller.show nothing happens.
If I do application.showFormInDialog() at least it shows something…
But I believe this is more due to a module framework I’m working with than a Servoy bug.

So far I’ve managed to show the form, but I still lose reference to the form whenever I call solutionModel.getForm(_form) to change the aspect of the elements.

Thanks for the help

Cheers

nromeou:
Rob, how do I make solutionModel.newForm take the JSForm object I already have??
Otherwise it’s no use to change a form if you have to create it from scrach later.

The problem is that you keep a handle to the form but you also call solutionModel.removeForm(), so the solution model does not know about the form anymore.
you should either call solutionModel.newForm() to create the form from scratch, or not call solutionModel.removeForm() to modify the existing form.

Rob

The problem is I must do removeForm in order to change the solutionModel or else an exception is thrown.

In any case, should I choose to make the form from scratch, is it okay if the form already exists in developer??
Or is it better if it doesn’t??

I think I’ll have to learn how to set all the properties of the form.

Thanks for the help.

Cheers

Rob,

I’ve been testing your newForm solution.
But now the problem is that the form I’m creating form scratch needs to be added to a tabpanel to be displayed.
So now the Stale form(s) detected exception is my problem since I cannot remove nor create from scratch the form containing the tabpanel.

I’m kinda stuck here.

What do you think should be my next move??

Is there no way whatsoever to change a form without removing it before??
For what you proposed I’m assuming there is also no way to reinstate the changed form other than build it form scratch.

Thanks for the help

Cheers

You dont have to call removeForm to not get the stale exception

The key is that history.remove() must be possible (but if the form is visible then that is not an option)

But if you only change the ui of the form then controller.recreateUI() does what you want to do after you have altered the form.

I have exactly the same issue :

The first time the code is run, it runs fine.
The second time the jsMailForm variable is empty;

Ouput first time :

remove done
JsForm= com.servoy.j2db.scripting.solutionmodel.JSForm@1dc84f1

Output second time :

remove done
JsForm=

b.t.w. displayMails is an existing form

So what am I doing wrong. I am not very experienced in using the solution model. ( but will be soon ;-) )

	// Remove the displayMails form from the current history, to destroy any active form instance
	//
	var success = history.removeForm('displayMails')

	if (success) {
		solutionModel.removeForm('displayMails')
		application.output('remove done')
	}
	else
	{
		application.output('remove not done')
	}

	
	// create an instance of the dislayForm
	//
	var jsMailForm = solutionModel.getForm('displayMails');
	application.output('JsForm= '  + jsMailForm)

hmm that is weird, the first time you also shouldn’t get a form back…
Because you removed it.

is there something between these 2 lines:

// create an instance of the dislayForm
   //
   var jsMailForm = solutionModel.getForm('displayMails');

?

because else your comment is just wrong, because you don’t create an instance of the form by just calling getForm() that only returns an existing instance

My comment is wrong, yes.

I think it works the first time because ‘displayMails’ is an existing form (created in developer, not in solutionmodel)

Regards,

but you did call solutionModel.removeForm(‘displayMails’) before any getForm() right?
That should have removed it.
Make a case if that isn’t the case in your sample

I removed the

solutionModel.removeForm(‘displayMails’)

and now it works every time.

Is this because it is an existing form already created in developer ??

Regards,

I think we differ here about what should go wrong
What did you expect:

Ouput first time :

remove done
JsForm= com.servoy.j2db.scripting.solutionmodel.JSForm@1dc84f1

Output second time :

remove done
JsForm=

do you think that the first time is correct? and the second time is incorrect?
That is not the case, the second time is what always should happen because you call removeForm()
if you remove that call then the first time should just always happen because you are just getting he same existing form

Thanks Johan