Maintaining state, Separating presentation code from business logic – Apple WebObjects 5 User Manual
Page 41

C H A P T E R 4
HTML-Based Applications
A Programmer’s View of WebObjects
41
Apple Computer, Inc. January 2002
subcomponent. Like dynamic elements, reusable components appear in the
template as a
tag with a corresponding
closing tag,
allowing you to extend WebObjects’s repertoire of dynamic elements.
The WOExtensions framework provided with WebObjects contains many useful
reusable components like tables, radio button matrices, tab panels, and collapsible
content. In addition, Direct to Web provides reusable components for editing,
listing, selecting, inspecting, and querying enterprise-object instances.
Maintaining State
In addition to the components, each WebObjects application has a number of
sessions
and an application object.
A session represents a period during which a particular user is accessing your
application. Because users on different client computers (or multiple browser
windows) may be accessing your application at the same time, a single application
typically hosts more than one session at a time. Session objects encapsulate the state
of a single session. These objects persist beyond the HTTP request-response cycle,
and store (and restore) the pages of a session, the values of session variables, and
any other state that components need to persist throughout a session. In addition,
each session has its own copy of the components that its user has requested.
Session variables can be used in shopping cart applications to represent the items in
the shopping cart. Email applications can use session variables to keep track of
whether the user has logged in or not.
The application object is responsible for interfacing with an HTTP adaptor and
forwarding HTTP requests to a dispatcher that, in turn, passes them to the
appropriate session and component. The application object also passes the HTML
response from the active component back to the adaptor. In addition, the
application object manages sessions, application resources, and components.
Separating Presentation Code from Business Logic
In HTML-based WebObjects applications (as in all WebObjects applications),
enterprise objects encapsulate the application’s business logic and provide the
connection with the application’s databases. Since enterprise objects are objects,
they can appear as variables in components, sessions, or the application object. A