main returns the XML file instance, which is in fact the top level component

Whenever you need to access all variables of an XML file from within a local or imported user defined function, you need to pass the main XML file instance as parameter to your function.

If you call this parameter for example "topLevelCpn" in your function, you can then access main file component local variables.

topLevelCpn.subCpnName;

Note that application variables are accessed directly from everywhere including from within functions, without having to pass the main.

server side (http request) >


// Import of the Jset windows, dialogs, & message box library
<IMPORT@CLIENT NAME="Windows" CLASS="jset.client.lib.Windows"/>

// Import of a server side user defined method in a client side project file
<IMPORT@SERVER NAME="cpn" PATH="/addOn/cpn/lib/cpn.lib"/>

// Import of a client side user defined method in a client side project file
<IMPORT@CLIENT NAME="lib" PATH="/folderFromRoot/subFolder/file.lib"/>

<JSET CLASS="jset.gui.control.JsButton" ID="-1" STYLE="0xa00032">
	<RECT X="0" Y="0" W="80" H="20"/>
	<EVENT action{
		// client side local variable
		name = 'Chris';
		// client side global variable
		application['name'] = 'Chris';
		// invoke local function
		r1 = myFunction(main);
		// invoke imported function
		r2 = lib.myFunction(cpnName);

		icon=Windows.MB_WARNING;
		buttons=Windows.MB_YESNO;
		dlg=new Windows.msgBox(caption,message,icon+buttons);
		btn=dlg.doModal();
		if(btn != ID_YES) return false;
		btn = new Windows.msgBox();
	}>
</JSET>


abort aborts processing

abort;
Remember to close your queries before aborting, as if you close (myQuery.close();) them after aborting this code will not be processed and they will remain unclosed.

server side code >



eval(param) allows to evaluate expressions

server side code >



for(i=0; i < 100; i++;) {...;} loop with for, use break & continue

// there is no loop instruction on the client side
// so for methods as well, only the for() can be used
for(i = 0; i < 100; i++;) 
{
	if (x==1) continue;
	else if (x==90) break;
	z = 3;
}

server side code >



getNumber(string) returns a number out of a number having a string format

nbr = getNumber(string);

server side code >



getType(object) returns object type

type = getType(param);

server side code >



if / else if and else conditions

if(v != null) value = v ; else value = 0;

if(getSelected() != null) 
{
	record = getSelected();
	uid = record.getAttribute('uid');
}
else record = null;


if(...) 
{
	if(...)...else...;
}
else
{
	if(...)
	{
		if(...) {...} else{...}
	} 
	else
	{
		...
	}
}

server side if / else expressions >



param.length() returns strings and arrays length.

// use .length() (Jset syntax), not .length (javascript syntax)
len1 = arr.length();
len2 = str.length();
len3 = qry.length();

server side code >



trace(param) is used to output the value of a variable, object or expression in the Java VM console

If you have requested a Jset server license (start Jset/server/Jset.exe then jset /g), the Jset server will automatically output error messages in the command prompt console.

server side code >



getString(param) converts an object representing a string into a real string

abc = getString(load(path));
rdr = getString(cpnName.getData());
nbr = getString(123);
str = getString(a + b);
obj = getString(getType(object));

server side code >



fullString.index(stringToFind) returns -1 if not found or first position of stringToFind in fullString

// use index() (Jset syntax), not indexOf() (javascript syntax)
fullString = 'This is the full string in which we search';
pos = fullString.index('which');

server side code >



string.lower() converts a string into a lower case string

// at the end, str will be = to 'chris'
<. str = 'Chris';>
<. str = str.lower();>
<. trace(str);>

server side code >



fullString.replace(stringToFind, stringToUse) replaces all occurrences of a stringToFind by stringToUse

// example
fullString.replace('find this string','replace by this string');

server side code >



string.split(sep) converts an separated string (param is delimeter) into an array.

// set a string with items separator (,)
str = 'Chris,Pierre';

// this str length will be equal to 12
strLen = str.length();

// convert the string into an array with split()
arr = str.split(',');

// the array length will be equal to 2
arrLen = arr.length();

// each array position represents an array item
item_1 = arr[0];
item_2 = arr[1];

You can now loop the array with for().

server side code >



fullString.subString(startInt, endInt) returns the subString of the fullString

server side code >



cpnName.getColor(cpnColorCode) returns the color value of a component color code



cpnName.setColor(cpnColorCode,colorValue) sets a component color code to the color value



dataCpnName.getSelected() returns a data component selected record

<EVENT action{
	// ex with action event (when a data component is clicked);
	// selected record value of the current component (the one in which the event is defined).
	record = getSelected();
	// or
	record = this.getSelected();
	// another component selected record value .
	record = dataCpnName.getSelected();
}>
You can now use the getAttribute() method te get the value of every field for this record.


getAttribute(record[fieldName]) returns a data component record field value

<EVENT action{
	record = getSelected();
	if(record != null) value = getAttribute(record['uid']);
}>


getService(dbClientName) returns a database object on which you can apply SQL statements

Use the database client (dynamic/static) name defined in your host configuration file a getService() parameter. db = getService(dbClientName); You can now apply other database instructions on the db object, such as runQuery() and runUpdate().

server side code >



db.runQuery(sql) to perform SQL SELECT operations

Execute SELECT SQL statements on your database.
When used on a dynamic client, the SQL SELECT statement has to be very basic, but supports WHERE and ORDER BY clauses.
In this case, result sets with their updates are automatically updated in the client ram.

// set the database service object
db = getService('Jset');
// create your SQL statement
sql = 'SELECT * FROM CTR WHERE eu = 1 ORDER BY ctrEN;';
// execute the query under a local variable name called query
query = db.runQuery(sql);

// you can do the same in one line of code like this:
query = getService('Jset').runQuery('SELECT * FROM CTR WHERE eu = 1 ORDER BY ctrEN;');

server side code >



db.runUpdate(sql) to perform SQL INSERT, UPDATE, & DELETE operations

The runUpdate() instruction can only be used with a database configured as a dynamic client in the host configuration file.

You must use a dynamic client and INSERT, UPDATE, or DELETE statement with this instruction.

// use runUpdate() only on a dynamic Jset client, and only with INSERT, UPDATE, OR DELETE
result = getService('dbClientName').runUpdate('INSERT ...;');
// or
db = getService('dbClientName');
sql = 'INSERT INTO...;';
uid = db.runUpdate(sql);
// uid will be the newly created record value (value of auto number field).

server side code >


All XML components can receive events.
Events must be declared within the JSET XML tags, so declare them just before the closing tag (...) of an XML component.
Events coding (also called client side coding) uses the same syntax than methods.


built event received by the main component of an XML file

This event is only received by the top level component of an XML file.

The event value is an array of 2 variables:
event[0] returns 1 if this XML file instance is a new instance, otherwise 0.
event[1] returns null if no param has been sent to this file instance, otherwise the object.

<EVENT built{
	// test if event[0] equals 0 or 1
	if(event[0] == 1) trace('This is a new file instance, its state is the initial state');
	else trace('This is an existing file instance, its state is the last state in which it was');
	// test if event[1] param exists, see getFileInstance(path, param, reload);
	if(event[1] != null) param = event[1];
}>
See also getFileInstance()


create event

The event is called for each component after the component has been created.
It sometimes necessary to apply some methods to the components after it has been created, as a few components objects are a sum of many different components, such as the Jset editor.
<EVENT create{
	trace('component has been created');
}>


browse(url[, target]) launch a browser window from a Jset applet

browse('http://www.yahoo.com','_blank');


getFileInstance(path[, reload, param]) to load an XML file instance, before you add it to a container

param = new Array(2);
param[0] = 'Chris';
param[1] = 'Pierre';
leftFile = getFileInstance('/folder/subFolder/file.app',0,param);
myContainer.add(leftFile);
The path param (string) is from the applet code base.

The reload (true/false) indicates whether you wish to load the last file instance (in the state it was), or if you wish to load a new file instance (reload) of the XML file. Note that when reloading a new file instance, it reloads it from the client side ram (and not from the server if it has it), and from the server it is the first time, or if the previous one was unloaded (fileInstanceName.close();) from the ram. In the built event of the loaded file, the value of event[0] will be 1 if the file instance is a new one, otherwise 0.

The param is an object you can pass as a param to the loaded file. It will be received as event[1] in the built event of the loaded file.

See also built event.


load(path [, params])


<IMPORT@CLIENT NAME="pth" PATH="/addOn/file/lib/pth.lib">

<FUNCTION@CLIENT myFunction(instance,otherParam)
{
	prm = instance.prm;
	type=getString(getType(prm)).lower();
	trace(type);
	if(param.index('array') != -1) trace('prm is an array of '+prm.length()+' variables.')
	else if(prm.index('bag') != -1) trace('prm is an bag and contains '+prm.keys().length()+' variables';);
	else if(prm.index('int') != -1) trace('prm is a int and equals to '+prm+'.');
	else if(prm.index('double') != -1) trace('prm is a double and equals to '+prm+'.');
	else if(prm.index('string') != -1) trace('prm is a string ('+prm+') of '+prm.length()+' characters.');
	trace('----------------');
	return type;
}>

<JSET CLASS="jset.gui.JsContainer" ID="-1" STYLE="0x1030">
	<RECT X="0" Y="0" W="-1" H="-1"/>

	<EVENT built{
		prm = 'abc';
		prm2 = 123;
		type = myFunction(main,prm2);
		path = '/folder/subFolder/file.ext';
		folder = pth.folder(path);
	}>
</JSET>
Local functions and functions located in an imported library file can be called from event code.

server side libraries >


server side libraries imports >

Some libraries must be imported at the top of a file to have the possibility to use them from within the file, and some others are implicitely imported for you so that you can use them without having to declare them.

Note that you can import them in a header file to have them accessible from all files in that folder, and in files in sub-folders as well, as long as your sub-folders do not have their own headers without the import.

Import Jset native & external APIs libraries with NAME / CLASS
<IMPORT@CLIENT NAME="Exports" CLASS="jset.util.lib.Exports"/>
<IMPORT@CLIENT NAME="Windows" CLASS="jset.client.lib.Windows">

Import your own (user defined) libraries with NAME / PATH
<IMPORT@CLIENT NAME="pth" PATH="/addOn/file/lib/pth.lib">
// IMPORT will import a library on both client & server sides

<IMPORT@CLIENT NAME="srv" PATH="/addOn/lib/srv.lib">
// IMPORT@CLIENT or IMPORT@CLT will import a library client side only


To use for a method, it must either be imported or defined at the top of the page calling it.

Jset methods can be imported to your projects When using a method You can import existing and your own libraries into your projects.



Importing your own methods instead of pl When located in the imported library file, this method must be called like this:
returnedValue = libName.functionName([param1,param2,...]);

if not returning any value:
libName.functionName([param1,param2,...]);


Functions return only one value.

If you need to return more than one value, return a new Array(size) or a new Bag().

If you wish to update variables/objects located in the file instance calling the method without having to return them, simply pass theit names as parameters preceeded by the & character. This way, when you update them in the method, they are automatically updated in the file instance as well.

Also, functions do not necessarily need parameters.

If you do not wish to return the method code on the client side, you can import it like this: You can also use @SRV instead of @SERVER.

Server side methods have access to global variables without having to pass any parameter.

dteTme = new Date(); Creates a date object with the now value.
dateObject = Date.parse(dateString,format); Creates a date object out of a string, format is the date format of the string.
dateObject = Date.format(dateObject, format); Formats a date object, format is the format you wish to use.
moveBy(param, int) dateObject.moveBy(param, int);
Moves dateObject to another date, param must be one of the following:
Date.DAY_IN_MONTH or 0x0020000
Date.DAY_IN_WEEK or 0x0040000
Date.DAY_IN_YEAR or 0x0010000
Date.HALF or 0x0000100
Date.HOURS or 0x2000000
Date.MINUTES or 0x4000000
Date.MONTH or 0x0000400
Date.QUARTER or 0x0000200
Date.SECONDS or 0x8000000
Date.WEEK or 0x0001000
Date.WORK_DAY or 0x0080000
Date.YEAR or 0x0000010
Date formats:

yy -> Year, 2 digits
yyyy-> Year, 4 digits
M -> Month (1-2 digits)
MM -> Month(2 digits)
MMM -> Month, short text
MMMM-> Month, text
d -> day of month (1-2 digits)
dd -> day of month (2 digits)
ddd -> day of week, short text
dddd-> day of week, text
h -> AMPM hour (1-2 digits)
hh -> AMPM hour (2 digits)
H -> 24 hour (1-2 digits)
HH -> 24 hour (2 digits)
m -> minutes (1-2 digits)
mm -> minutes (2 digits)
s -> seconds (1-2 digits)
ss -> seconds (2 digits)
Q -> Quarter (1 digit)
S -> Half/Semester (1 digit)
w -> week of year (1-2 digits)
ww -> Week of year (2 digits)
t -> AMPM, short text
tt -> AMPM, long text
D -> Day of week (1 digit)
DD -> Day of year (1-3 digits)
DDD -> Day of year (3 digits)
Formats in bold are the recommended formats to use.

If you are going to save dates/times in a database text field, it is advised to use this format :

Date only > yyyy/MM/dd
Time only > HH:mm
Date & time > yyyy/MM/dd HH:mm

Using the reverse recommended format will allow you to perform SQL ORDER BY clause and preserve date time consitency, as in this case alphanumeric sort will perform a logical date/time sort.

server side code >


<IMPORT@CLIENT NAME="Exports" CLASS="jset.util.lib.Exports"/>

server side exports >


Format.decode(string) Returns a decoded string out of an URL encoded string.
Format.encode(string) Returns an URL encoded string out of string.
Format.fromUTF8(string) Use with load, not stream.
Returns a string out of an UTF8 string.
Format.sqlString(string) Appends a single quote at the beginning and end of a string, and preserves single quotes in the string.
Used to construct sql statements.
Format.toCString(string) Use with File.load(), not stream.
Returns the formatted representation of the string.
' will be \'
carriage return will be \r\n
tab will be \t
Format.toHtmlString(string) Returns the string in html encoded format.
Usefull for accents and other weird characters.
Format.toUTF8(string) Use with load, not stream.
Returns the UTF8 representation of the parameter.

Math.abs(number) Returns positive value.
So even if your number is negative, you will get a positive value.
Math.fromBase(number, base) Returns an integer out of a number in the specified base.
Math.int(number) Returns an integer (no decimals) out of a number.
Note that this does not round the number, so 1.9 will return 1.
Math.log(number) Returns natural logarithm value of number.
Math.random() Returns a random number between 0 and 1.
Math.round(number, precision) Returns a rounded number.
Use 10 to round to 1 digit after the comma (0.1) to take into consideration the 2rd number after the comma.
Use 100 to round to 2 digits after the comma (0.01) by taking into consideration the 3rd number after the comma...
Use 20 to round to closest 0.05...
Math.toBase(int, base) Returns a string in this base.
Used to get representation of a number in another base.
Math.toHex(int) Treats the number like a not signed number.
Usefull to get hex color codes (Jset XML colors (0x......) and html color codes).
Returns an hex string.


Math operators reference

&& Logical AND operator, you can also type "AND".
|| Logical OR operator, you can also type "OR"
== Checks if two items are equal.
!= Checks it two items are unequal (equivalent to NOT (A = B), but faster).
< Checks if A is less than B (2 < 3 is true, 3 < 3 is false).
<= Checks if A is less than or equal to B (2 < 3 is true, 3 < 3 is true).
> Checks if A is greater than B (2 > 3 is false, 3 > 2 is true).
>= Checks if A is greater than or equal to B (2 >= 2 is true, 3 > 2 is true).
+ Adds two items, meaning is following:
If A or B is an array, the result is an array containing all items of A and all items of B.
Or, if A or B is a string, the result is a string containting the concatenation of A and B.
Or if A and B are integers, the result is an integer.
Or if A and B are numbers, the result is a number.
Or if A or B is a number, the result is a number.
- Substracts two numbers, the result is an integer if both items are integers, a number otherwise.
* Multiplies two numbers, the result is an integer if both items are integers, a number otherwise.
% Remainder of the division of two integers, always an integer value.
^ Mathematical power (a^b).


new Array(size) variables list, accessed by position

Array objects are used to save a list of variables. Each variable within the array does not have an name but is accessed by its position.
<EVENT built{
	a = new Array(2);
	a[0] = 'Chris';
	a[1] = 1969;
	trace('My array length is equal to '+a.length());
	a[2] = 'Third array item';
}>

server side code >



new Bag() variables list, accessed by name

Bag objects are used to save a list of variables. Each variable within the bag has a name.
<FUNCTION myFunction()
{
	b['name'] = 'Chris';>
	b['birthDate'] = 1969;>
	trace('My bag length is equal to '+b.length());
}>

server side code >



new Parameters() to create parameters you will post

// client side or method code
params = new Parameters();
params.add('name','Chris');
params.add('birthYear','1969');
params.add('path','C:/folder/subFolder/');
params.add('myFile',fileName, fileContent);
load('/serverFile.jset',params);
// serverFile.jset

// get current year
<. year = Date.parse(new Date(),'yyyy');>

// output name and age
<: post['name'];> is now  <: getNumber(year) - getNumber(post['birthYear']);>

// save posted file
<. File.save(path+post['myFile'].value,post['myFile'].content);>


RENDERS text, image, symbol, and mixed (ArrayRenderItem) renders


server side variables >



name client side local variables, these variables are accessible from any event in an XML applet file.

Use application variables to set a variable value for all XML files of a client side (Java 1.0 applet) project.

server side local variables >



application[name] client side global variables, these variables are accessible on all XML applet files.

Use application variables to set a variable value for all XML files of a client side (Java 1.0 applet) project.

server side global variables >