Table of Contents Previous Section

Components

Components are a part of each WebObjects application that you write. Each component defines the content, presentation, and behavior of a page or portion of a page. You can write scripted components in WebScript (the WebObjects scripting language) or compiled components in Objective-C.

Scripted components generally consist of three files:

Scripted and compiled components play the same role, and are created in essentially the same way. However, instead of using a script file, compiled components use an Objective-C class.

The files of a component are organized in a component directory. The name of the directory has the same base name as the name of the component, but the extension .wo. For example, the HelloWorld example has a WebScript component named Main and a corresponding component directory named Main.wo.

The template, script, and declarations files in the component directory also have the same base name, and each file type has its own extension. Template files have the extension .html, declarations have the extension .wod, and scripts have the extension .wos. Thus, the Main component has the files Main.html, Main.wos, and Main.wod, as shown in Figure 6. In addition to these three files, a component directory may also contain images and other resources used by the component.

Figure 6. The Contents of a Component Directory

Note: Not all components represent an entire page. Some components represent only a portion of a page. You can extract common data and functionality from components for whole pages into smaller, reusable components. These smaller components can be nested as subcomponents inside a component representing a whole page. For more information, see the "Creating Reusable Components" chapter.

The Main Component

The component for the first page of a WebObjects application is generally named Main. When a user starts a session with a WebObjects application, he or she can specify the name of the first page, but it is uncommon to have to do so. If no page is specified, WebObjects applications look for a component named Main to represent the first page.

Where Components Go

Generally, you put the components of a WebObjects application in a directory with the same name as the application. For example, the HelloWorld example has a corresponding directory named HelloWorld that contains its component directories.

WebObjects application directories such as HelloWorld can go anywhere under the <DocumentRoot>/WebObjects directory. You can create application directories immediately under <DocumentRoot>/WebObjects, or you can create hierarchies of directories within <DocumentRoot>/WebObjects to organize application directories however you wish.

As shown in Figure 7, the HelloWorld application directory is located in <DocumentRoot>/WebObjects/Examples.

Reusable WebObjects components used by multiple applications aren't usually kept in application directories. Rather, they are located directly under <DocumentRoot>/WebObjects so they can be accessed by all the applications that use them.

Figure 7. HelloWorld Application Directory

 

Table of Contents Next Section