Documentation Archive Developer
Search
Table of Contents Previous Section

State in the Page

To store state in the page, you must do two things:

You specify the page session store this way:

	// Application.java
	public Application() {
		super();
		this.setSessionStore(SessionStore.pageSessionStore());
	}



	// Application.wos.
	- init {
		[super init];
		[self setSessionStore:[WOSessionStore pageSessionStore]];
		return self;
	}
Next, you must add a form to each page of the application and place a WOStateStorage object within the form. You do this in WebObjects Builder by adding a Custom WebObject to the form and then using the Inspector panel to specify that the type of element is "WOStateStorage".)

The WOStateStorage element maps to an HTML input element of type "hidden." The "hidden" input type contains text that is not displayed in the user's browser. For example, using state in the page, the HTML source for the Guess page of the SessionStores example would look something like this:

	<FORM METHOD=Post ACTION=someAction>
		Can you guess my favorite digit?<BR>
		<SELECT NAME="guesses">
			<OPTION>1
			<OPTION>2
			...
			<OPTION>9
		</SELECT>
		<INPUT TYPE="hidden" NAME="hiddenState" VALUE="previousGuesses">
		<INPUT TYPE="submit" VALUE="Guess">
	</FORM>
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:

Table of Contents Next Section