Table of Contents Previous Section

Application awake

The application awake method is invoked when the application receives its first request and never again. It's common to initialize global variables in an application awake method. For example, the Application.wos script in the DodgeLite example initializes the global variable dodgeData from a file:

- awake {
    id filePath = [WOApp pathForResource:@"DodgeData" ofType:@"dict"];
    dodgeData = [NSDictionary dictionaryWithContentsOfFile:filePath];
}

See DocumentRoot/WebObjects/Examples/DodgeLite for the complete DodgeLite source.

The WOWebScriptApplication class defines the awake method, which is invoked when an instance receives its first request from a WOApplicationAdaptor object. WOWebScriptApplication's awake implementation invokes the awake method defined in the corresponding Application.wos if one exists. You can subclass WOWebScriptApplication and override awake to perform any necessary initialization. It is more common, however, to implement the awake method in an application script.

Because the application awake method is invoked only once in an application's lifetime, changing a scripted application awake method has no effect on a running WebObjects application that has received its first request. You must restart an application for changes to a scripted application awake method to have an effect.

In addition to using the application awake method to initialize global variables, you can also use it to configure the application's behavior. For example, you can set a session timeout and enable component caching:

// Timeout sessions that have been inactive for more than 2 minutes.
[WOApp setSessionTimeOut:120];
[WOApp setCachingEnabled:YES];

Table of Contents Next Section