Apple WebObjects 3.5 User Manual

Page 21

Advertising
background image

The Ingredients of a WebObjects Application

21

files. A component may not need a code file at all; it may need only a
template file and a declarations file. Another component might have a code
file but no template file or declarations file. Plus, if you create a component
using Project Builder or WebObjects Builder, you’ll get a fourth file,
Component

.api

, which contains API that should be made public to other

components.

The next three sections describe more completely these template, code,
and declarations files.

Template

You use a template (

Main.html

) to specify how the page you’re creating should

look. This file typically contains static HTML elements (such as

<H1>

or

<P>

) along with some dynamic elements. Dynamic elements are the basic

building blocks of a WebObjects application. They link an application’s
behavior with the HTML page shown in the web browser, and their
contents are defined at runtime.

An HTML template can also contain a reference to another component
(called a reusable component or subcomponent) that represents a portion of an
HTML page. This reference behaves just like a reference to a dynamic
element.

Code or Script File

You use the code file (

Main.wos

) to define your component’s attributes and

actions. The attributes are called variables or instance variables, and the
actions are called methods.

With WebObjects, you can write your code file in one of three programming
languages: Java, Objective-C, or WebScript. Java is the language of choice
for many people; others prefer Objective-C. Because both of these
languages require compiling, they aren’t as well suited to rapid prototyping
as a scripting language is. For this reason WebObjects provides a scripting
language named WebScript, described in the chapter “The WebScript
Language” (page 163). You may have noticed that the examples directory
mentioned previously offers examples in all three languages.

Note:

Java support is not available on the Mach or HP-UX platform.

The

Main.wo

component shown in Figure 1 uses a WebScript file to define its

behavior. (The

.wos

extension signifies WebScript.) If you want to use Java

or Objective-C, the code file resides at the same level as the

Main.wo

directory

Advertising