State storage strategies – Apple WebObjects 3.5 User Manual

Page 120

Advertising
background image

Chapter 7

Managing State

120

// Java DodgeLite Main.java
public Component displayCars()
{

SelectedCars selectedCarsPage =

(SelectedCars)application().pageWithName("SelectedCars");

...

selectedCarsPage.setModels(selectedModels);
selectedCarsPage.setTypes(selectedTypes);
selectedCarsPage.setPrices(selectedPrices);
...
selectedCarsPage.fetchSelectedCars();

return (Component)selectedCarsPage;

}

// WebScript DodgeLite Main.wos
- displayCars
{

id selectedCarsPage = [[self application]

pageWithName:@"SelectedCars"];

...

[selectedCarsPage setModels:selectedModels];
[selectedCarsPage setTypes:selectedTypes];
[selectedCarsPage setPrices:selectedPrices];
...
[selectedCarsPage fetchSelectedCars];

return selectedCarsPage;

}

The new component is created by sending a

pageWithName:

message to the

application object. A series of messages is then sent to this new object to set its
state before the object is returned as the response page.

Component state persists until the component object is deallocated, an action
that can occur for various reasons, as described in the section “Controlling
Component State” (page 135).

State Storage Strategies

WebObjects gives you the option of storing state in various ways:

In the server

. State is maintained in memory within a WebObjects application.

In the page

. State is embedded in the HTML page that’s returned to the user.

Advertising