beautypg.com

Subcomponents and component references – Apple WebObjects 3.5 User Manual

Page 86

background image

Chapter 5

WebObjects Viewed Through Its Classes

86

associate particular events in the client applet (such as clicking a button) with
the invocation of methods in the server.

State is synchronized between the client and the server in three phases:

1. When a page is first generated, the server sends the client all state for which

there are bindings.

2. Before an action is invoked in the server, the client sends the server any of

its state that has changed.

3. After the action is completed, the server sends the client any of its state that

has changed.

This last synchronization occurs only if no new page is returned to the browser.
When a method invoked remotely through an applet action binding returns

null

,

it signals that, instead of returning a new page, the server should resynchronize
its state with the applets on the page. WebObjects takes a snapshot of the
changes in state in the server so that only the state that has changed is sent back
to the client.

Note

: The last two phases of the synchronization cycle can be initiated only on the

browser side. That is, except for the first “initialization” phase, the server
component can react only to an action triggered in an applet. The component
cannot unilaterally update the state of an applet when its own state changes.

Subcomponents and Component References

A “node” in a template’s object graph can represent a subcomponent (also called
a reusable component) as well as a dynamic or static HTML element. A
dynamic element called a component reference represents all occurrences of the
subcomponent in the parent component. At runtime, the component reference
binds itself to the separate instances. Figure 26 is an example of an object graph
for a page with a subcomponent.

A subcomponent can fire actions against its parent component (using

performParentAction:

), and if the parent’s state changes, its state is synchronized

accordingly. In other words, its state is updated to reflect changes according to
its bindings with the parent.

An element ID is assigned to each instance of a subcomponent. When the chain
of request-handling messages traverses an object graph and reaches the
component reference, it resolves references to its instances according to the
element ID of each instance. Components keep track of all their
subcomponents by storing them in an internal dictionary using element IDs as
keys.