Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > WebObjects Developer's Guide


Table of Contents Previous Section

Component Initialization

A component object's init method is invoked when the component object is created. Just how often a particular component object is created depends on whether the application object is caching pages. For more information, see "WebObjects Viewed Through Its Classes". If page caching is turned on (as it is by default), the application object generally creates the component object once and then restores that object from the cache every time it is involved in a user request. If page caching is turned off, the component object is freed at the end of the request-response loop.

Note: The pageWithName: methods shown in the section "Action Methods" always create a new component object, even if page caching is turned on.

A component object's init method usually initializes component variables. For example, the following method initializes a component variable named departments:

// WebScript Department.wos
id departments;
- init {
id departmentsPath;

[super init];
departmentsPath = [[[self application] resourceManager]
pathForResourceNamed:@"Departments.array"
inFramework:nil
languages:[[self session] languages]];
departments = [NSArray arrayWithContentsOfFile:departmentsPath];
return self;
}

Table of Contents Next Section