SDK error on add a widget to page

1
Hi All, I have a problem when I try to add a widget like simple Text or anything using the SDK to a page.  When I create a new app and there is a page it works, but the "LayoutCallArgument" is out of the "LayoutCall" and this is the problem, Why this happen?  Maybe the Modeller did not understand where to insert the LayoutCallArgument.  I am using auto generated code from Reverse engineering for simple page with only text: var translation1 = texts.Translation.create(model); translation1.languageCode = "nl_NL"; translation1.text = "Tekst"; var translation2 = texts.Translation.create(model); translation2.languageCode = "en_US"; translation2.text = "Hello"; var text1 = texts.Text.create(model); text1.translations.push(translation1); text1.translations.push(translation2); var clientTemplate1 = pages.ClientTemplate.create(model); clientTemplate1.template = text1; // Note: for this property a default value is defined. var text1_1 = pages.DynamicText.create(model); text1_1.name = "text1"; text1_1.content = clientTemplate1; // Note: for this property a default value is defined. var layoutGridColumn1 = pages.LayoutGridColumn.create(model); layoutGridColumn1.weight = 12; layoutGridColumn1.widget = text1_1; var layoutGridRow1 = pages.LayoutGridRow.create(model); layoutGridRow1.columns.push(layoutGridColumn1); var layoutGrid1 = pages.LayoutGrid.create(model); layoutGrid1.name = "layoutGrid1"; layoutGrid1.rows.push(layoutGridRow1); //Bellow is where something must be changed I think var layoutCallArgument1 = pages.LayoutCallArgument.create(model); layoutCallArgument1.widget = layoutGrid1; var layoutCall1 = pages.LayoutCall.create(model); layoutCall1.layout = model.findLayoutByQualifiedName("NavigationLayouts.Sidebar_Full_Responsive"); layoutCall1.arguments.push(layoutCallArgument1); // End of region var translation3 = texts.Translation.create(model); translation3.languageCode = "en_US"; translation3.text = "Page Title"; var text2 = texts.Text.create(model); text2.translations.push(translation3); var temp = pages.Page.createIn(unit); temp.name = "TestPage"; temp.canvasWidth = 1200; temp.canvasHeight = 600; temp.layoutCall = layoutCall1; // Note: for this property a default value is defined. temp.title = text2; // Note: for this property a default value is defined. temp.popupResizable = true;   When I try to update an  app and I add a new page using the code above, or I simply try to add widget like Text to already created page without content, this error is throwned by the Modeller  System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null. Parameter name: value    at Mendix.Modeler.WebUI.Forms.Widgets.FormCalls.LayoutCallArgument.set_ParameterId(LayoutParameterIdentifier value) in C:\jenkins\workspace\WebUI-Build-6\modeler\Mendix.Modeler.WebUI\Forms\Widgets\FormCalls\LayoutCallArgument.Generated.cs:line 45    --- End of inner exception stack trace --- All elements have  auto generated ID so the ID of the 'LayoutCallArgument' is not a problem, maybe the ID of a missing element cause the error, as there is not an element the id is null. Of course it is possible that this is a bug. I've tryed adding IDs  but there is not an effect.  I am using latest npm packages for model and platform, also my IDE version is 6.10.2 (I installed Mendix 7.0.2 but the same error appear) and Did anybody in this forum ever created an app with  page and simple widget inside using SDK ? If so,  please tell me where is the problem or post the code.  Thanks.  
asked
3 answers
5

Cool that you are making such good use of the SDK!

You have run into a limitation that we have not solved yet. There is a workaround. I'll share it with you but only if you don't tell anyone else :-)

Let me first explain the funny model of layouts "calling" pages. We see a layout as a "function" where the placeholders can be seen as parameters. A page "calls" the layout and the outermost widgets on a page are passed as arguments to the layout. A layout call argument tells you where to place what widget. The code below creates a layout argument for a given placeholder name. Afterwards you still need to set the widget property.

Good luck!

export function createLayoutArgument(layoutCall: pages.LayoutCall, name: string) {
    const result = pages.LayoutCallArgument.createIn(layoutCall);
    (result as any)["__parameter"].updateWithRawValue(layoutCall.layoutQualifiedName + "." + name);
    return result;
}

Update: I updated the code so that it also works if you pass the no-implicit-any compiler flag to the Typescript compiler.

answered
0

 

I did it, it works but... When one create a new app must use "parameterName" not "parameter" because somehow the new app is created using Mendix v 6.0.0. Also when I create new LayoutGridRow or LayoutGrid, there is always one element added, but not by me. So I have to perform "clear()" on the array before pushing elements inside. I've checked the array and there is one element after initialization always by default. Also the text on the widgets is not shown instead the text is "Empty caption" doesn't matter will I create new app or update existing one?

answered
0

How do you use the "createLayoutArgument" function? We've tried different values but we end up with "value cannot be null" exception.

answered