Using JavaScript in zeroCode built sites
 

 

 
The Role of Client-side Scripting
 

To fully decouple a generated application’s user interface from its business logic and database access mechanisms, zeroCode-built sites use a macro-expansion engine called FreeMarker. FreeMarker is a reputed, extensible, freely available open-source environment that specifically addresses the need for marrying HTML with object-driven architectures and provides an easy way to keep graphic design separate from application logic. To use it, zeroCode encapsulates HTML in templates. FreeMarker runs on the server and retrieves data, while the HTML renders on the client, along with the DHTML. DHTML is a combination of cascading style sheets and JavaScript/VBScript. The preferred language to use for DHTML is JavaScript in the zeroCode environment, although VBScript can be used if the browser supports it.

JavaScript is an extension of HTML that helps the programmer do special things like formatting and building advanced user interfaces with Web pages. While HTML is the skeleton that gives a document its appearance and structure, JavaScript is the brains and the muscle that give it life. VBScript is a competing scripting language that can be used equally well to extend client-side functionality.
Using JavaScript in a Site
In a zeroCode-built site, the web server expects JavaScript files to be located in the …/webFiles/javaScript subdirectory of the site on the server. Designers can build new functionality using JavaScript and upload the relevant source-files into this directory.  In building such functionality, designers must recognize that the architecture of their site, as generated by zeroCode, is predictable and scalable and the code that they construct must reflect that structure. Specifically, designers can take one of the two approaches:
1 Build functionality that can be included in each template that needs that functionality
2 Build functionality that can be included in a meta-template, such that all future pages generated using this meta-template include the functionality built.
The most effective mechanism to follow is to first develop code that works in one or more templates and, after proving usability, migrate that upwards to a meta-template. In building JavaScript that works well in a zeroCode-built site, the issues below need to be recognized and planned for specifically.
A zeroCode meta-template includes two levels of complexity in using FreeMarker: FreeMarker is invoked first at gen-time (when the site is generated and the templates are created) and again at run-time (when the page is served up). At gen-time, FreeMarker is used more as a control mechanism, with its ability to expand macros being very important. At run-time, FreeMarker is used as much to pull in data from the Java objects as to marshal that data (using zeroCode-specific functions) and make it presentable on the client. The language in the JavaScript files needs to work with this complexity, if it is to be usable in a meta-template. This is not an issue if the JavaScript functionality planned will be used only in templates. Click here to read more about templates and meta-templates.
As a designer, you must be aware of the FreeMarker data items that are available in a given context. These items include everything in the related UDM and can be invoked in the standard FreeMarker syntax. Typical data items are the items that come from the objects that you include and the additional items that the zDE automatically includes in certain cases, like the list-control-related counts and other values. If the JavaScript function is to be used in a meta-template, the references to those data items must be specified using special (recursive) syntax that the meta-templates includes. There are other variables available at gen-time that you can use in a meta-template to control the manner in which a site is generated. Click here for a list of node-attributes that you can use.
If you choose to implement your JavaScript functionality at the meta-template level, so that it is included in every page that zeroCode generates, you will need to decompose your functions into stuff that happens at gen-time and stuff that happens at run-time. At gen-time, you need to ensure that the generation process includes the exact statements that you want to see in the template. You do this by adding the appropriate language to the meta-template.
When in doubt, look through the manner in which the sample functions are implemented and documented here. Or call for support!
Rich Text Editor
Rich Text Editor is a brainchild application derived from JavaScript. The JavaScript provides both flexibility and consistency like any other high level language. One of the more practical things that JavaScript does at this time is increase the aesthetics and friendliness of websites by adding author-specific user events to HTML pages. With DHTML serving the UI features, JavaScript handles all the functional part of Rich Text Editor.
Pagination:
In cases where you need to display a large number of records in an HTML table, pagination obviously comes in handy.  The pagination mechanism puts in a specified number of records into each html, thus giving equal intervals and also making the navigation easier for you.  In zeroCode, too, you will find a similar mechanism that helps you display a large number of records on the HTML. To know more about the uniqueness of this mechanism, click here.
XL Port
XL Port is yet another feature that zeroCode has introduced using javascript. This facilitates export of data or records from a given UDM to an excel sheet. You can save such data on your machine. Read more about it.