Associations and client-side java components – Apple WebObjects 3.5 User Manual

Page 85

Advertising
background image

How HTML Pages Are Generated

85

START:Calendar {

selectedDate = startDate;
callBack = "mainPage";

};

In this example, Main is the parent component and Calendar is the child
component. The

startDate

variable belongs to the parent component while

selectedDate

is a variable of the child component. A change in the parent

component instance variable is automatically communicated through the
association to the child variable. Conversely, a change in value in the child
component variable is communicated to the parent variable. Component
synchronization occurs at the beginning and end of each of the three
request-handling phases of a component (

takeValuesFromRequest:inContext:

,

invokeActionForRequest:inContext:

, and

appendToResponse:inContext:

). Synchronization is

performed through the accessor methods of both components.

This aspect of synchronization has implications for developers. Because
WebObjects invokes explicitly implemented accessor methods many times
during the same request-response loop, your accessor methods must have
no side effects. Instead, they should simply set a variable’s value or return a
value. And if they return a value, there should be some way for WebObjects
to set the value.

This rule applies also when the binding involves a parent or a child
component’s method instead of an instance variable. To illustrate this,
assume that

startDate

is a method of the Main component instead of an

instance variable. Even in this case, WebObjects attempts to synchronize

startDate

with the

selectedDate

value. In other words, WebObjects attempts to

invoke a

setStartDate:

method and raises an exception if such a method does

not exist.

See the chapter “Creating Reusable Components” (page 91) for more on
state synchronization between child and parent components.

Associations and Client-Side Java Components

Client-side Java components, like server-side dynamic elements, use
associations to synchronize state with the parent component. However, the
association class they use is not the same. Instead of using

next.wo.Association

(the WOAssociation equivalent in Java), they use

next.wo.client.Association

, and

this Association class is downloaded to the client along with the component
itself.

Keys for a client-side component fall into two groups: state bindings and
action bindings. State bindings form the basis for state synchronization by
associating state in the applets with state in the server. Action bindings

Advertising