...
Stoc |
---|
While the Servoy platform is based entirely in Java, one does not need to write any Java during the course of development or deployment.
Instead, all business logic is implemented using JavascriptJavaScript. Javascript JavaScript was selected because it is an internet standard, easy to learn and as such, the most widely used scripting language on the planet. Javascript JavaScript is far more productive than coding in pure Java and Servoy provides robust APIs with which to quickly and easily implement business logic.
Note | ||
---|---|---|
| ||
Developers who are familiar with Javascript JavaScript may cite issues with browser support and speed of execution. However, it is worth noting that Servoy does not deploy any JavascriptJavaScript. All code written in Servoy is deployed using Mozilla's Rhino project, which is an open-source, Java-based Javascript JavaScript implementation. This means that:
|
...
Scope defines the domain in which code is executed and subsequently determines the namespace by which scripted objects are referenced. Javascript JavaScript code (functions and variables) may be defined in the following two scopes:
solution-wide scopes:
Code Block | ||
---|---|---|
|
...
scopes.globals.createNewCustomer(); // invokes the global method defined in the 'globals' scope |
form scopes
Code Block | ||
---|---|---|
|
...
...
forms.customers.controller.newRecord(); // invokes a form object from another scope
|
compared to:
Code Block |
---|
function createNewCustomer(){ // a method defined within the 'customers' form scope
controller.newRecord(); // invokes the same form object from within the form's scope. Notice the fully qualified namespace is NOT required
}
|
...
From context menu:
From the Solution Explorer tree, navigate to the
...
active solution > Scopes > myScope > variables node.
Right-click the variables node and select Create Variable from the pop-up menu.
Choose a variable name, a data type and optionally choose an initial value
...
. The variable declaration will be generated in the
...
myScope.js file, which will be opened in the Script Editor.
From Solution Explorer toolbar:
From the Solution Explorer tree, navigate to the
...
active solution > Scopes > myScope > variables node.
...
Select the variables node and click the Create Variable button from the lower toolbar in the Solution Explorer.
Choose a variable name, a data type and optionally choose an initial value
...
. The variable declaration will be generated in the
...
myScope.js file, which will be opened in the Script Editor.
From context menu:
...
...
From Solution Explorer toolbar:
...
...
...
...
...
...
From context menu:
...
...
...
...
From Solution Explorer toolbar:
...
...
...
...
...
...
From context menu:
...
...
...
...
...
From Solution Explorer toolbar:
...
...
...
To implement some business logic, create a method and fill in the body of the Javascript JavaScript function with executable code.
The following example implements the functionality to advance the selected record index on a form:
Code Block |
---|
function nextRecord(){
var index = controller.getSelectedIndex(); // store the current index
controller.setSelectedIndex(index+1); // increment the index by 1
}
|
The example uses the form's controller object, part of the Javascript JavaScript API provided by Servoy.
Developers need not memorize the API or look it up. The scripting APIs are self documenting, and code fragments can easily be inserted into the Script Editor.
Any scripting API (including methods written by a developer) can be inserted directly into the Script Editor in two ways.
From context menu:
...
...
...
...
...
...
From Solution Explorer toolbar:
...
...
...
...
...
...
...
Any scripting API's commented sample code can be inserted directly into the Script Editor in two ways.
From context menu:
...
...
...
...
From Solution Explorer toolbar:
...
...
...
...
Tip | ||
---|---|---|
| ||
Any scripting API (including methods written by a developer) can be auto-completed using key strokes. To To use auto-complete, begin typing the code you wish to executebe executed, then hit ctrl Ctrl+space on the keyboard. A type-ahead list of available scripting objects will appearallowing for you to choose from as you typechoosing from them while typing. This is a highly productive and accurate way to write code when you have one has become more familiar with the APIs. |
Tip | ||
---|---|---|
| ||
If you are unfamiliar with Javascript syntax, that's OKFor developers not so familiar with JavaScript, there is an easier way to use the JavaScript API. In the Solution Explorer, navigate to the JS Lib node. This object node contains a list of APIs for dealing with the Javascript JavaScript language and native data types. It even contains syntax completion for common statements in the Statements node. |
Suvideo | ||||
---|---|---|---|---|
|