Page Events

Each page has a lifecycle; it is created and attached to an engine. It will render itself. It is placed in a pool for later reuse. Later, it comes out of the pool and is attached to a new engine to start the process again. There are cases where objects, especially the components embedded somewhere within the page, need to know about this lifecycle.

IPage can produce a number of events related to its lifecycle. PageRenderListener is a listener interface for determining when the page starts and finishes rendering (this includes rewind renders related to the ActionLink component).

Figure 4.3. Page Render Sequence

Page Render Sequence

The call to commitPageChanges() is very important. It is not possible to make any changes to persistant page properties after this method is invoked; doing so will throw an exception.

Figure 4.4. Page Rewind Sequence

Page Rewind Sequence

Page rewinds, which are related to the Form and ActionLink components, also perform a render operation in order to restore dynamic state on the page. The PageRenderListener events are still fired. The event listeners can invoke isRewinding() on IRequestCycle to determine whether this is a normal render, or for rewind purposes.

The PageDetachListener interface is used by objects that wish to know when the page is detached from the application, prior to be stored into the page pool (for later reuse). This is used by any components that maintain any independent state.

Figure 4.5. Page Detach Sequence

Page Detach Sequence

This cleanup occurs at the end of the request, after a response has been sent to the client web browser.

The engine knows when the HttpSession has been invalidated because the container will invoke valueUnbound(). It loads and rolls back each page, then invokes cleanupPage() to allow the page to gracefully cleanup any held resources.

Components that implement one of these interfaces usually override the method finishLoad() (from AbstractComponent) to register themselves with the page.