It is important to understand the lifecycle of a session to know which hooks to customize. Figure 132 depicts the lifetime of a session:
- When the user accesses a Seaside application for the first time a new session instance is created and the root component is instantiated. Seaside sends the message
WAComponent>>initialRequest:to the active component tree, just before triggering the rendering of the components. Specializing the method
initialRequest:enables developers to inspect the head fields of the first request to an application, and to parse and restore state if necessary.
- All subsequent requests are processed the same way. First, Seaside gives the components the ability to process the callbacks that have been defined during the last rendering pass. These callbacks are usually triggered by clicking a link or submitting a form. Then Seaside calls
WAComponent>>updateUrl:of all visible components. This gives the developer the ability to modify the default URL automatically generated by Seaside. Then Seaside redirects the user to the new URL. This redirect is important, because it avoids processing the callbacks unnecessarily when the user hits the Back button. Finally Seaside renders the component tree.
- If the session is not used for an extended period of time, Seaside automatically expires it and calls the method
WASession>>unregistered. If the user bookmarked the application, or comes back to the expired session for another reason, a new session is spawned and the lifecycle of the session starts from the beginning.