Page History
Table of Contents | style | upper-roman
---|
Stoc |
Purpose
The Solution Model is a feature since Servoy version 4.1 which allows you to manipulate different kinds of objects on-the-fly through scripting. You can perform actions such as:
- Create objects and set their properties
- Clone objects
- Manipulate properties of existing objects
- Revert objects to its original design-time state
- Remove existing objects
What
...
It Is
The Solution Model is the blueprint of your developed solution. You can modify its blueprint during runtime, but the object still needs to be actually built to become available to the user. Compare it to building a house and where certain rules apply when you want to make changes to the already built house.
...
It's also possible to create new instances of a form within Servoy (by using the function application.createNewFormInstance()). These are copies of the actual house, rather than copies of the blueprint. It is not possible for the Solution Model to grab the properties of these copies, but only from the original. So when you try to grab the new instance of a form by using the Solution Model, then it will retrieve the original form from which the new instance has been created and not the new instance itself.
Limitations
Even though the Solution Model allows a wide variety of objects that can be manipulated, there are some limitations. The following objects are (currently) not included:
...
Note | ||
---|---|---|
| ||
Manipulating solutions and modules are not applicable for the Solution Model because they are not relevant during deployment. At this point the collection of solutions and modules have become one flat solution. Therefore, no (references to) solutions and modules can be made with the Solution Model. |
Functionality and
...
Basic Rules
The Solution Model has certain types of functions:
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 | Allows you to retrieve objects to be manipulated by the Solution Model |
New | Allows you to create new objects 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. |
With the Solution Model you can control different types of objects. Referring to these objects is done through so-called JS Objects and consist of constants, properties and/or functions.
The following list shows the objects which can be controlled by the Solution Model, its corresponding JS Object and from which JS Object it needs to be referenced from in order to use it:
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 |
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 |
Note | ||
---|---|---|
| ||
A list of all these JS Objects and their corresponding constants, properties and functions can be found under the SolutionModel node in the Solution Explorer of the Developer. |
...
Note | ||
---|---|---|
| ||
As of Servoy version 6 a new method exists, called servoyDeveloper.save(). By running this method in the Debug Client or the Command Console of the Developer, changes by the Solution Model are being pushed back and saved into the worspace. |
Examples
This section shows some (simple) examples of how different objects can be controlled with the Solution Model. Per object you will find how to:
...
Code Block |
---|
solutionModel.removeStyle('myStyle'); |
Global
...
Variables
To create a new global variable with name myGlobalVariable of type TEXT:
...
Code Block |
---|
solutionModel.removeGlobalVariable('myGlobalVariable'); |
Global
...
Methods
To create a new global method with name myGlobalMethod:
...
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.newFormVariablenewVariable('myFormVariable', JSFieldJSVariable.TEXT_FIELD ); |
To get existing form variable myFormVariable:
Code Block |
---|
var formVariable = form.getFormVariablegetVariable('myFormVariable'); |
To change its default value to abc:
...
To remove existing form variable myFormVariable:
Code Block |
---|
form.removeFormVariableremoveVariable('myFormVariable'); |
Form
...
Methods
To create a new form method with name myFormMethod:
Code Block |
---|
var formMethod = form.newFormMethodnewMethod('function myFormMethod() {controller.newRecord(); }'); |
...
Code Block |
---|
var formMethod = form.getFormMethodgetMethod('myformMethod'); |
To make it appear in the menu:
...
To remove existing form method myFormMethod:
Code Block |
---|
form.removeFormMethodremoveMethod('myFormMethod'); |
Form
...
Parts
To create a new body:
Code Block |
---|
var part = form.newPart(JSPart.BODY, 20); |
...
Code Block |
---|
form.removePortal('myPortal'); |
Tab
...
Panels
To create a new tab with name myTabPanel:
...
Code Block |
---|
solutionModel.removeRelation('myRelation'); |
Value
...
Lists
To create a new value list with name myValueList:
...