Table of Contents Previous Section

The Role of Scripts in a WebObjects Application

In developing WebObjects applications, you usually write your business logic as compiled Objective-C code (though you can write entire applications using just WebScript). You then use WebScript to provide your "interface logic." A WebScript script typically includes the following ingredients:

In most cases, a script has a corresponding declarations file and HTML template. The declarations file provides a mapping between the actions and variables defined in the script, and the HTML elements that will be dynamically generated and then substituted in the HTML template.The three files in a group have the same base name but different extensions; for example, Main.wos (script), Main.wod (declarations), and Main.html (template). These application resources are used by a corresponding WOWebScriptComponentController to prepare responses to user requests. Most commonly a WOWebScriptComponentController represents a single page in a WebObjects application, though it can also represent just a portion of a page.

In a WebObjects application you generally put each group of three files (the script, the declaration, and the HTML template) into a directory that has the same base name and the extension .wo. So, for example, you can have a directory Main.wo that contains the files Main.wos, Main.wod, and Main.html. Each group of three files is called a component. The script associated with a component (in this example, Main.wos) is called a component script.

Figure 1. The Contents of a Component Directory

The Application Script

Often, in addition to having multiple components (that is, subdirectories that contain a script, a declarations file, and an HTML template), a WebScript application also has an application script. This script is where you declare and initialize global and session variables. For more information on global and session variables, see the section "Variables and Scope."

The application script has the name Application.wos, and it resides immediately under the application directory.

Table of Contents Next Section