Table of Contents Previous Section

Initialization Methods

The application, session, and component objects in a WebObjects application receive two messages that allow the objects to initialize themselves. The two methods, init and awake, are invoked in both scripted and compiled instances of WOApplication, WOSession, and WOComponent subclasses. The main difference between the methods is when they are invoked.

When init and awake are Sent

When objects are created, they receive an init message. The init method gives the receiver an opportunity to initialize its state and behavior just after it is created. The initialization is effective over the lifetime of an object; this lifetime varies according to the object's type:

An object's awake method, on the other hand, is invoked at that point in each cycle of the request-response loop that the object begins to participate in request handling. This usually occurs right after init, except in those two cases noted above where an page is restored from a cache rather than created. In these cases, the awake method is invoked without a prior invocation of the init method.

See "How WebObjects Works" for a discussion of init and awake in the context of the request-response loop.

Table of Contents Next Section