Apple WebObjects 3.5 User Manual

Page 103

Advertising
background image

Intercomponent Communication

103

For the sake of illustration, consider a page that displays a value in two
different text fields—one provided by the parent component and one by
the child (see Figure 31).

Figure 31. Synchronized Components

Setting the value of either text field and submitting the change causes the
new value to appear in both text fields.

The parent’s declarations file reveals the binding between the two
components:

CHILDCOMPONENT: ChildComponent {

childValue=parentValue;

};

When a value is entered in a field and the change submitted, WebObjects
will, if needed, synchronize the value in the parent (

parentValue

) and child

(

childValue

) at each of the three stages of the request-response loop:

Before and after the components receive the

takeValuesFromRequest:inContext:

message.

Before and after the components receive the

invokeActionForRequest:inContext:

message.

Before and after the components receive the

appendToResponse:inContext:

message.

To synchronize values, WebObjects uses key-value coding, a standard
interface for accessing an object’s properties either through methods
designed for that purpose or directly through its instance variables. Key-
value coding always first attempts to set properties through accessor
methods, reverting to accessing the instance variables directly only if the
required accessor method is missing.

Given that synchronization occurs several times during each cycle of the
request-response loop and that key-value coding is used to accomplish this
synchronization, how does this affect the design of reusable component? It
has these implications:

You rarely need to implement accessor methods for your component’s
instance variables.

Advertising