The Otcl NeoWebScript™ Interface

Using an interpreter-safe version of MIT's Object Tcl, The Otcl NeoWebScript™ Interface brings object orientation to the NeoWebScript page developer. This interface allows the user to define classes for generating blocks of hypertext in Tcl, including tables and forms. An extensive "query" class has been created to interface to a Postgres95 database backend.

Theory of operation

The goal in developing objects is primarily to facilitate reuse. For example, one might want to display data from a database in a form. The same form might be used to enter new data, and is displayed with certain default information. Later the same (or slightly modified) form might be used to edit the original data. Otcl classes can be used to contain information about a form, the result of a query or a posting, and hand information off between them.

Before executing any class commands, the user executes a "using_otcl" command. This command load the Otcl package into the safe interpreters, and also sources in class.tcl which is found under httpd/conf. The classes documented hereafter can all be found in class.tcl.

In using the pre-defined classes given here, the user should think of defining the objects as the setup phase for the application. The actual work (and thus time) then used to make the queries, display the data, and pass information to and from the database.

Tk programmers will find the interface vaguely familiar, as items are declared with dot-separated pathnames which generally determine how hypertext objects are grouped together. Any object which implements the display method, must cause the object to return the HTML code which is represented by the data contained therein. display may be sent directly to an individual object, or it may be sent to a higher level object. It is up to the class defintion to call display for any subordinate objects. Note that the order of object creation will determine the traversal. Individual objects may support the enabled flag, and may consequently be disabled (object-name enabled 0). Objects are traversed and displayed in the order they are created. Some objects are context-sensitive. For example, an input object (eg. a select box or text input field) can be used anywhere, but if these objects are not displayed within a form, then they merely output plain text.

For example, consider the following code fragment:

form f
input f.fred -type selectbox -text {a line for fred} -name fred -size 10
input f.dave -type text -text {a line for dave} 
html [f display]

The form object f is created, which contains two members, f.fred and f.dave. The HTML returned by the call to [f display] resulting from the above code is an HTML form containing input field declarations with default text given above, as follows:

If no text value is declared for a form element, it is assumed that the form will be associated with query object (-query) and that this object contains either the results of a POST, or an SQL query. In either case the names of the response or the attributes of the query (must) correspond to the names of the input fields.

The last step in generating HTML for a form (or hypertext) object is to call the query method subst to substitute the actual values in the query object.

This is done in two phases because it makes implementation of the relationship of hypertext to a query more flexible. Any object which is asked to display itself will call the subst method if a query object has been associated with it (-query objectname). An object's display method may delay final substitution by emitting tcl code surrounded with brackets. The select input object uses this to make the correct item selected when an input item has been read from a query.

Common Methods

Option methods

All option methods take a single argument, and may be invoked when an object is created as -option value, or later on as a method to the object, ie. object-path option value. Note that option methods always take an argument (this is Otcl's style), so options that do not require an argument should just be set to "1" to enable it.

Commands

Classes

Future plans

Randy Kunkee
kunkee@neosoft.com