Child pages
  • Server Side Scripting

Versions Compared

Key

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

Table of Contents

Defining the server side scripting file in .spec

A component or service can have a serverside part, so that some of it's logic is executed on the server, ; in the spec file this is configured like:

Code Block
languagejs
title.spec file
"serverscript": "servoydefault/tabpanel/tabpanel_server.js",

Server-side code is build up the same as the client-side so you have $scope object with model/api/(since 8.3) handler/(since 8.3.1) servoyApi objects.

An example is the default tabpanel.

API methods (private, public) and calling them in client-side js, server-side js and solution code

What API methods can solution code, server side js and client side js call

Server side scripting can contain API methods defined in the spec of the component / service. These methods execute then directly server-side. When a certain API is called from Servoy solution scripting, Servoy will first check if that API is defined server side. If it is, it will just call the server side API method.

...

As this server side file can also have the implementation of the public API that is defined in the .spec file, you can handle complex things server side; this can be used as a performance enhancement so that the api call doesn't have to go to the client to execute at the moment the call is made from Servoy solution code.

The API call that is executed server-side could for example just update some model properties of the component/service; these will be sent automatically as one thing to the client when the server-side code is done. And then client can detect those model changes. Or server-side code could call directly a client side API method after doing some pre-processing for example. More complex components like tabpanel, grouping girds based on foundsets or services like form popup service heavily rely on server-side implementation both for public APIs (defined in "api" section in the .spec file and present in server-side scripting through $scope.api.xyz()) and for private implementations details from internalAPIs (defined in "internalApi" section of the .spec file and present in server-side scripting through $scope.xyz()).Server-side code is build up the same as the client-side so you have $scope object with model/api/(since 8.3) handler/(since 8.3.1) servoyApi objects.An example is the default tabpanel.

...

On the $scope.api object you can define the public api methods that you want to execute server side. The difference - compared to client side structure is that "internalApi"s from .spec file are defined directly on $scope compared to client - where "internalApi"s are defined in the same place as public api methods.

...