Table of Contents Previous Section

Synchronizing Parent and Child Components

WebObjects treats attribute bindings between parent and child components as potentially two-way communication paths and so synchronizes the values of the bound variables at strategic times during the request-response loop. This synchronization mechanism has some implications for how you design components.

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:


Figure 1. 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:

Synchronization is accomplished through 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. (The key-value coding mechanism is declared in the Enterprise Objects Framework, in EOKeyValueCoding.h. See the Enterprise Objects Framework Developer's Guide for more information.) Key-value coding always first attempts to set properties through accessor methods, only reverting to accessing the instance variables directly 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 for the design of reusable component? It has these implications:

Table of Contents Next Section