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


Table of Contents Previous Section

Component Awake

The component awake method is invoked immediately after the init method and each time the component object is restored from the page cache. Just as in init, you can implement an awake method that initializes component variables. For example, a component might have a shoppingCart variable that is a snapshot of the session's shoppingCart variable. Each time the component is restored from the cache, its shoppingCart variable should be updated with the session's shoppingCart:

// WebScript Car.wos
- awake {
shoppingCart = [[self session] shoppingCart];
}
In general, you use init or the component's constructor to initialize component instance variables instead of awake because init is invoked only at component initialization time, whereas awake is potentially invoked much more than that. If, however, you want to minimize the amount of state stored between cycles of the component action
request-response loop, you might choose to initialize component instance variables in awake and then deallocate them in sleep (by setting them to nil in WebScript or null in Java). For more information, see the chapter
"Managing State".

Table of Contents Next Section