Page History
...
Type | Purpose |
---|---|
Clone | Copies of a certain objects can be created |
Create | These factory functions allow you to create specific objects which can be used at properties of other objects |
Get | Allow Allows you to retrieve obejcts which can objects to be manipulated by the Solution Model |
New | Allow Allows you to create new objects which can to be manipulated by the Solution Model |
Remove | Allow you to remove existing objects |
wrapMethodWithArguments | Allows you to get a method, wrap it with arguments and assign it to an event. |
...
Object | JS Object | Referenced from JS Object | |||
---|---|---|---|---|---|
Calculations | JSCalculation |
| |||
Styles | JSStyle |
| |||
Global variables | JSVariable |
| |||
Global methods | JSMethod |
| |||
Forms | JSForm |
| |||
Components | JSComponent | JSForm | |||
Form variables | JSVariable | JSForm | |||
Form methods | JSMethod | JSForm | |||
Form parts | JSPart | JSForm | |||
Beans | JSBean | JSForm | |||
Buttons | JSButton | JSForm | Components | JSComponent | JSForm |
Fields | JSField | JSForm | |||
Labels | JSLabel | JSForm | |||
Parts | JSPart | JSForm | |||
Portals | JSPortal | JSForm | |||
Tab panels | JSTabPanel | JSForm | |||
Tabs | JSTab | JSTabPanel | |||
Relations | JSRelation |
| |||
Relation items | JSRelationItem | JSRelation | |||
Value lists | JSValueList |
| |||
Media | JSMedia |
|
...
Components basically work as an umbrella for all objects which are referenced from the JSForm object. By retrieving an object as a component, you can change properties which are shared by all these objects or conveniently clone the object including its referenced objects and properties. Check the examples at components for more information.
When creating objects you need to make sure that the same object with the same name does not already exists. In this case you need to choose another name or remove the existing object.
As explained as an analogy in a previous section, some changes made with the Solution Model have such an impact that on other existing objects, that some of them need to be destroyed and recreated again.
Note | ||
---|---|---|
| ||
Changed objects which affect a visible form but is not that form itself or any object referenced from that form should result in removing be removed (or reverting) the form and redisplay it. Changed objects of a form or reverted) redisplayed. Changed form objects any object referenced from that form should be recreated or removed (or reverted) and redisplayed. Check the examples below at forms for more information. |
By default, changes made by the Solution Model are not persistent and are only valid for the current session in which these changes are made.
...
- Create an object
- Retrieve an existing object
- Change a property of an object
- Remove an existing object
Calculations
...
Create
As described in a previous section, the Solution Model includes some factury functions which allow you to create certain layout object which can be used at forms.
To create a new calculation with name myCalculation on table customers of server example_data which returns 1blue line border of width 1 and use that on an existing form:
Code Block |
---|
var calculationborder = solutionModel.newCalculationcreateLineBorder('function myCalculation() { return 1; }', JSVariable.INTEGER, 'db:/example_data/customers'); |
...
1, 'blue');
var form = solutionModel.getForm('myForm);
form.borderType = border;
|
Calculations
During development, calculations can be created as stored or unstored. As soon as the name of a calculation corresponds with a database column, it automatically becomes a stored calculation. The same rule applies for the Solution Model.
To create a new calculation with name myCalculation on table customers of server example_data which returns 1:
Code Block |
---|
var calculation = solutionModel.getCalculationnewCalculation('myCalculation', 'function myCalculation() { return 1; }', JSVariable.INTEGER, 'db:/example_data/customers'); |
To get the existing calculation myCalculation on table customers of server example_data:
Code Block |
---|
var calculation = solutionModel.getCalculation('myCalculation', 'db:/example_data/customers');
|
To output whether or not this calculation is a stored one:
...
Note | ||
---|---|---|
| ||
When changing an existing form which has already been loaded, you need to refresh it before the end of the method by using controller.recreateUI(). If the form is not refreshed then this will result in an error. You When changes are made to underlying objects which have effect on the loaded form, you need to remove (or revert) the form and and redisplay it again. Check out the examples below on how to do this. You also need to take the following into consideration:
|
...
Note | ||
---|---|---|
| ||
You can only revert a form when it exists as a physical form created in design-time. Reverting a form which is created by the Solution Model will result in an error. |
Form variables
...
Components
Components allow you to retrieve all objects which are referenced from the JSForm object. By retrieving an object as a component, you can change properties which are shared by all these objects or conveniently clone the object including its referenced objects and properties.
To retrieve component with name myButton:
Code Block |
---|
var formVariablecomponent = form.newFormVariablegetComponent('myFormVariable', JSField.TEXT_FIELDmyButton'); |
To get existing form variable myFormVariablehide the element:
Code Block |
---|
component.visible = true;
|
To retrieve all available components on the form:
Code Block |
---|
var formVariablecomponents = form.getFormVariablegetComponents('myFormVariable'); |
To change its default value to abcthe width of all elements to 200:
Code Block |
---|
formVariable.defaultValue for (var i = 'abc'0; |
...
i < components.length; i++) {
components[i].width = 200;
}
|
To clone an existing component:
Code Block |
---|
formsolutionModel.removeFormVariablecloneComponent('myFormVariablemyClonedComponent', component); |
Form methods
To create a new form method with name myFormMethod:
Code Block | ||
---|---|---|
Note | ||
| ||
To test to what type of object the retrieved component belongs to, you need to use the JavaScript operator instanceof. For example, if you want to find out if the component is a button, use: component instanceof JSButton |
Form variables
To create a new form variable with name myFormVariable:
Code Block |
---|
var formVariable = form.newFormMethodnewFormVariable('function myFormMethod() {controller.newRecord(myFormVariable', JSField.TEXT_FIELD); }'); |
To get existing form method myFormMethodvariable myFormVariable:
Code Block |
---|
var formMethodformVariable = form.getFormMethodgetFormVariable('myformMethodmyFormVariable'); |
To make it appear in the menuchange its default value to abc:
Code Block |
---|
globalMethodformVariable.showInMenudefaultValue = true'abc'; |
To remove existing form method myFormMethodvariable myFormVariable:
Code Block |
---|
form.removeFormMethodremoveFormVariable('myFormMethodmyFormVariable'); |
Form
...
methods
To create a new body:form method with name myFormMethod:
Code Block |
---|
var partformMethod = form.newPart(JSPart.BODY, 20newFormMethod('function myFormMethod() {controller.newRecord(); }'); |
To retrieve the existing body partget existing form method myFormMethod:
Code Block |
---|
var partformMethod = form.getPart(JSPart.BODYgetFormMethod('myformMethod'); |
To change its background to whitemake it appear in the menu:
Code Block |
---|
partglobalMethod.backgroundshowInMenu = 'white'true; |
To remove the existing body partform method myFormMethod:
Code Block |
---|
form.removePart(JSPart.BODYremoveFormMethod('myFormMethod'); |
...
Form parts
To create a tree view with name myBeannew body:
Code Block |
---|
var beanpart = form.newBean('myBean', 'com.servoy.extensions.beans.dbtreeview.DBTreeView', 200, 200, 300, 300newPart(JSPart.BODY, 20); |
To get existing bean myBeanretrieve the existing body part:
Code Block |
---|
form.getBean('myBean'var part = form.getPart(JSPart.BODY); |
To change its anchoring to top, left and bottombackground to white:
Code Block |
---|
beanpart.anchorsbackground = SM_ANCHOR.NORTH | SM_ANCHOR.WEST | SM_ANCHOR.SOUTH'white'; |
To remove the existing bean myBeanbody part:
Code Block |
---|
form.removeBean('myBean'removePart(JSPart.BODY); |
...
Beans
To create a new button tree view with name myButton and text Text and attaching global method myGlobalMethod to it myBean:
Code Block |
---|
var globalMethodbean = solutionModelform.getGlobalMethodnewBean('myGlobalMethodmyBean'); var button = form.newButton('Text, 'com.servoy.extensions.beans.dbtreeview.DBTreeView', 0200, 0200, 80300, 20, globalMethod300); button.name = 'myButton'; |
...
To get existing bean myBean:
Code Block |
---|
var button = solutionModel.getButtonform.getBean('myButtonmyBean'); |
To change its height to 30anchoring to top, left and bottom:
Code Block |
---|
buttonbean.heightanchors = 30 SM_ANCHOR.NORTH | SM_ANCHOR.WEST | SM_ANCHOR.SOUTH; |
To remove existing button myButtonbean myBean:
Code Block |
---|
form.removeButtonremoveBean('myButtonmyBean'); |
Components
Components basically work as an umbrella for all form elements. By retrieving a form element through a component, you can clone the element including its properties.
Or, If you want to change properties which are common to all elements, you can do this through components instead of having to retrieve each individual object separately.
Note | ||
---|---|---|
| ||
To test to what type of object the retrieved component belongs to, you need to use the JavaScript operator instanceof. For example, if you want to find out if the component is a button, use: component instanceof JSButton |
...
Buttons
To create a new button with name myButton and text Text and attaching global method myGlobalMethod to it:
Code Block |
---|
var component globalMethod = solutionModel.getGlobalMethod('myGlobalMethod'); var button = form.getComponentnewButton('myButton'Text', 0, 0, 80, 20, globalMethod); |
To hide the element:
Code Block |
---|
component.visiblebutton.name = true'myButton'; |
To retrieve all available components on the formget existing button myButton:
Code Block |
---|
var componentsbutton = formsolutionModel.getComponentsgetButton('myButton'); |
To change the width of all elements to 200its height to 30:
Code Block |
---|
for (var i = 0; i < components.length; i++) { components[i].widthbutton.height = 20030; } |
To remove existing button myButton:
Code Block |
---|
form.removeButton('myButton');
|
Fields
To create a new text field with name myField with form variable myFormVariable as its dataprovider:
...
Code Block |
---|
solutionModel.removeMedia('myMedia'); |
Note | ||
---|---|---|
| ||
For all examples of functions, properties and functions, check out the programming reference on the wiki or select one form the Solution Explorer in the Developer and choose Move sample. |