With HAHTtalk Basic, you can easily extend the functionality of your HAHTsite Web applications beyond what you can do with HTML or CGI programs. In a HAHTsite HAHTtalk Basic project, you can use HAHTtalk Basic in these ways:
1 You can add in-line code to a page, intermixed with other HAHTsite elements such as text, pictures, and forms. The code can be a simple expression, a single line, or a complete block of code. See “In-line code” on page 48.
2 You can insert expressions and method calls in many of the dialogs in the IDE — for example, a text box can be initialized with the value of an expression, and a form’s action can be a call to a HAHTtalk Basic subroutine. See “Invoking an expression or a subroutine from a dialog box” on page 50.
3 You can insert code in predefined places within the source code for a page, using the HTML editor’s Server-side Code view. See “Adding code in Server-side Code view” on page 52.
4 You can create separate source files, with functions and subroutines that can be shared by all of the pages in an project and that can be reused in other projects. In addition to creating or importing HAHTtalk Basic source files, you can import compiled HAHTtalk Basic files as well. See “Adding HAHTtalk Basic files to a project” on page 60.
HAHTsite Server Object Model
Much of this book describes classes and methods in HAHTsite’s Server Object Model, which controls the structure of a HAHTsite Web application. With the Server Object Model, you can perform tasks such as reading data passed on the URL, writing HTML data, and controlling session timeout, as well as managing data source connections, setting form field values, and controlling access to dynamic pages.
The Server Object Model is implemented in Java. However, it is equally accessible from HAHTtalk Basic projects, and the online help for the Server Object Model shows both the Java and HAHTtalk Basic syntax to call each method. A few methods are not meaningful in a HAHTtalk Basic project, and for those methods the syntax is shown as “n.a.”
For more information about Java, you may wish to look at Chapter 4, “Calling Server-side Java from HAHTtalk Basic.” You may already be familiar with calling CreateObject or CreateJavaObject, to access COM objects or Java objects from Basic. However, HAHTsite’s Server Object Model has a set of built- in objects. You do not need to instantiate them in order to call their methods.
External logic
From your HAHTtalk Basic code you also have access to capabilities such as CORBA, COM/DCOM, and native methods. For more information, see the table below.
External logic Where described
Server-side Java Chapter 4, “Calling Server-side Java from HAHTtalk Basic”
In-line code
The ability to intermix HAHTtalk Basic code with other elements (such as text, pictures, Widgets, and form elements) gives you a powerful tool for
dynamically changing the content of Web pages. You can use this technique for many purposes — for example:
• to control the flow of logic on the page
• to create “internationalized” pages that contain text in different languages from which a user can select
• to modify values read in from a database or from the URL
To maintain the WYSIWYG look of your pages, you’ll probably want to minimize the amount of code that you place directly onto a page. You can do this by creating functions and subroutines in a project’s source pages and calling them from your Web pages. With this approach, you can also share functions and subroutines among the project’s Web pages.
This example shows a form whose first-name and last-name text box values are being overridden by global variables from in-line code at the top of the page.
Windows DDE calls Online help Sending SMTP email messages Online help FTP operations to a remote server Online help Using the shell command to
create an external process
Online help
Socket operations Online help UNIX API system calls
Windows API systems calls Online help
Besides adding entire lines of code, you can also add expressions. An expression can include variables, constants, operators, and functions, as long as it resolves to a single value. Here are two examples:
Date$
Haht.getRequest().getURLField("txtCity")
In the HAHTtalk Basic source, the IDE includes the expression in a Print statement.
To add a HAHTtalk Basic expression to an HTML page
1 On the page, click where you want the expression to appear. 2 Click the Server-side Expression button .
3 Type the expression.
4 By default, expressions are displayed in red in the HTML editor. However, you can override this setting in Tools > Options > Editor.
To add a statement to an HTML page
To convert existing text to an expression or statement 1 Select the text you want to convert.
2 Click either the Server-side Expression button or the Server-side Statement button .
To format the output of an expression or statement
You can format the output of a HAHTtalk Basic expression or statement, just as you can format text that you type directly on the page.
1 Select the paragraph or characters you want to affect.
2 To modify the paragraph properties, choose Edit > Paragraph... or make a selection from the Paragraph Styles toolbar.
3 To modify the character properties, choose Edit > Character.... or make a selection from the Character Styles toolbar. (If you modify the font color, the new color will be displayed in the browser, but not in the IDE.)
Invoking an expression or a subroutine from a dialog
box
The second way you can customize your project is by invoking expressions or subroutines inside a dialog box — for example, to set link properties or form properties. From the HAHTsite IDE and IP User’s Guide, you’re probably aware of the many places in property-sheet dialog boxes that allow you to use an expression rather than a field name or a constant, or that allow you to call a subroutine instead of a dynamic page as a link or form action.
Dialog box expressions
To substitute an expression for a field name or constant, prefix the expression with "==". For example, in the link properties, you could set the query string to contain the value of the (String) variable "CityCode":
On the destination page, you could retrieve the information this way: Print aRequest.getURLField("Code")
Notice in the example the use of "/*" and "*/" bracketing the expression. You must use this construction when you want to use an expression in a
name/value attribute pair, or when it appears in the middle of a script. However, if you simply want to set an attribute to the value of an expression, you can use ==expression.
The expression must evaluate to a character string. Dialog box subroutine calls
In addition to using expressions, you can call user-defined subroutines (not
functions) from several dialogs in the IDE, such as the Form Properties dialog and the Link Properties dialog. For example:
• It can be the default action that takes place when the user submits a form, or the action tied to one of the form’s buttons.
Obviously, the content of your subroutine will be determined primarily by what you want it to do. However, if its effect is to display a page, it should emit the <HEAD>...</HEAD> and <BODY> and </BODY> HTML tags.
For an annotated view of a typical page, see “What’s in a HAHTtalk Basic page?” on page 53.
Adding code in Server-side Code view
The third way to customize your project is to add directly to the server-side code for a page. When you build or publish your project, the IDE generates a
pagename.hbs file for every dynamic page. (These generated files are stored in your project’s sites directory and don’t appear in the project window.) If you add in-line code to the page, it’s inserted in the HAHTtalk Basic source. However, you may want to make other additions to the code for a page — for example, you might want to add an include statement, add some initialization code, or add variables to the page. The HTML editor’s Server-side Code view lets you view the source code for a page, and lets you make additions, in predefined places, that will be preserved when the page is regenerated. (Note - you cannot change the generated source code; you can only add to it.) To view and add to the server-side code for a page
1 Open the page in the HTML editor.
2 Select View > Server-side Code, or click the Server-side Code view button . Here are some points to note:
• The white areas mark places where you can insert code.
• The grayed-out areas mark generated source code, which is read-only. • If you make changes in Server-side Code view, and then return to
Normal view or HTML Tags view, you will see your changes reflected.
• If the Server-side Code view button is disabled, be sure that you have
saved the page (and that it is dynamic).
For more information on this process, see the note that follows. Behind the scenes: How does Server-side Code view work?
To keep from overwriting your additions, the IDE must keep your code separate from the code it generates. When you add code in Server-side Code view, your code is translated into HTML tags and kept in the project’s HTML
file for this page. If you look at the page in HTML tags view, you will see sections like this:
<P><SCRIPT language="hahttalk-statement"><!-- Print date$--></SCRIPT></P>
When you build or publish the project, the code for the dynamic page is generated from the HTML file.