Apple WebObjects 3.5 User Manual
Page 125

State Storage Strategies
125
When WebObjects generates a response page containing a
WOSessionStore element, it packages the session state by archiving the
session object—and consequently, all the component objects that it
contains—using classes and methods defined in the Foundation
framework. The session and components are archived into an NSData
object. (In Java, NSData is called next.util.ImmutableBytes.) The NSData
object is then asked for its ASCII representation, which is written into the
HTML page as hidden fields. (See the class specification for NSArchiver in
the Foundation Framework Reference for more information on archiving.)
WebObjects writes as many hidden fields as are necessary to contain the
state data.WOStateStorage’s
size
attribute specifies the maximum size of
each of these hidden fields (500 bytes in the example above). The
size
attribute is provided because browsers differ in the amount of text that they
allow within a single hidden field. Most browsers have no problem with the
default value for
size
(1000 bytes).
When the user submits the HTML page to the server, the process is
reversed. The application’s page session store restores the session state by
recombining the ASCII data it finds in the hidden fields into the original
ASCII archive, converting the ASCII archive to its binary, NSData,
representation, and then unarchiving the session object and its contents
from the NSData object.
There are some limitations inherent in storing state in the page:
•
Forms are required.
Because state is stored in an input element—which
according to the HTML specification must exist within a form
element—you must structure your application around forms. If you
want session state to be available at any point in the application, each
page of the application must have a form, and that form must contain a
WOStateStorage element.
If a page has multiple forms, you must include the page state data in
each form. If a form lacking this data is submitted, the application will
no longer have the state information it needs.