Table of Contents Previous Section

Synchronizing Attributes in Parent and Child Components

Because WebObjects treats attribute bindings between parent and child components as potentially two-way communication paths, it 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 (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:

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:

Table of Contents Next Section