Child pages
  • Implementing Business Logic

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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
titleNote

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:

  1. All methods are executing in Java (orders of magnitude faster than interpreted JavascriptJavaScript)
  2. No business logic is ever exposed or executed in the browser, thereby eliminating browser support issues.
  3. Experienced developers can optionally use 3rd-party java APIs, mixing Java code directly in their Servoy methods.

...

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 scopes:

...

  1. From the Solution Explorer tree, navigate to the active solution > Scopes > myScope > variables node.

  2. Right-click the variables node and select Create Variable from the pop-up menu.

  3. 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.

...

  1. From the Solution Explorer tree, navigate to the active solution > Scopes > myScope > variables node.

  2. Select the variables node and click the Create Variable button from the lower toolbar in the Solution Explorer.

  3. 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.

...

  1. From the Solution Explorer tree, navigate to the active solution > Forms > myForm > variables node.
  2. Right-click the variables node and select Create Variable from the pop-up menu.
  3. Choose a variable name, a data type and optionally choose an initial value. The variable declaration will be generated in the myForm.js file, which will be opened in the Script Editor.

...

  1. From the Solution Explorer tree, navigate to the active solution > Forms > myForm > variables node.
  2. Select the variables node and click the Create Variable button from the lower toolbar in the Solution Explorer.
  3. Choose a variable name, a data type and optionally choose an initial value. The variable declaration will be generated in the myForm.js file, which will be opened in the Script Editor.

...

  1. From the Solution Explorer tree, navigate to the active solution > Scopes myScope node.
  2. Right-click the myScope node and select Create Method from the pop-up menu.
  3. Choose a method name. The method declaration will be generated in the myScope.js file, which will be opened in the Script Editor.

...

  1. From the Solution Explorer tree, navigate to the active solution > Scopes > myScope node.
  2. Select the myScope node and click the Create Method button from the lower toolbar in the Solution Explorer.
  3. Choose a method name. The method declaration will be generated in the myScope.js file, which will be opened in the Script Editor.

...

  1. From theSolution Explorertree, navigate to the active solution > Forms > myForm node.
  2. Right-click themyFormnode and selectCreate Methodfrom the pop-up menu.
  3. Choose a method name. The method declaration will be generated in themyForm.jsfile, which will be opened in the Script Editor.

...

  1. From the Solution Explorer tree, navigate to the Active Solution active solution > Forms > myForm node.
  2. Select the myForm node and click the Create Method button from the lower toolbar in the Solution Explorer.
  3. Choose a method name. The method declaration will be generated in the myForm.js file, which will be opened in the Script Editor.

...

To implement some business logic, create a method and fill in the body of the Javascript JavaScript function with executable code.

...

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.

...

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource, (i.e. active solution > Forms > myForm > controller).
  2. In the list of methods and properties provided in the lower part of the Solution Explorer, right-click the method or property that you wish to invoke wished to be invoked and select Move Code. The code will be copied into the Script Editor and will be referenced with the correct namespace for the current scope. You It may need be needed to fill in specific arguments.

...

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource.
  2.  In the list of methods and properties provided in the lower part of the Solution Explorer, select the method or property that you wish to invoke wished to be invoked and click the Move Code button in the lower toolbar of the Solution Explorer. The code will be copied into the Script Editor and will be referenced with the correct namespace for the current scope. You It may need be needed to fill in specific arguments.

...

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource, (i.e. active solution > Forms > myForm > controller).
  2. In the list of methods and properties provided in the lower part of the Solution Explorer, right-click the method or property that you wish to invoke wished to be invoked and select Move Sample. A verbose, commented sample will be copied into the Script Editor.

...

  1. From the Solution Explorer tree, navigate to and select the node of a scriptable resource.
  2. In the list of methods and properties provided in the lower part of the Solution Explorer, select the method or property that you wish to invoke wished to be invoked and click the Move Sample button in the lower toolbar of the Solution Explorer. A verbose, commented sample will be copied into the Script Editor.
Tip
titleTip

Any scripting API (including methods written by a developer) can be auto-completed using key strokes.

To use auto-complete, begin typing the code you wish to executebe executed, then hit Ctrl+space on the keyboard. A type-ahead list of available scripting objects will appear allowing 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
titleTip

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.

...