Table of Contents Previous Section

Intercomponent Communication

Reusable components can vary widely in scope, from as extensive as an entire HTML page to as limited as a single character or graphic in a page. They can even serve as building blocks for other reusable components. When a reusable component is nested within another component, be it a page or something smaller, the containing component is known as the parent component, and the contained component is known as the child component. This section examines the interaction between parent and child components.

In the AlertPanel example above, you saw how the parent component, in its declarations file, sets the attributes of the child component:

ALERT: AlertPanel {
    alertString = alertTitle;
    alertFontColor = "#A00000";
    alertFontSize = 6;
    infoString = alertDescription;
    infoFontSize = 4;
    infoFontColor = "#500000";
    tableWidth = "50%";
};

Each of the AlertPanel's attributes is set either statically (for example, alertFontSize = 6) or dynamically, by binding the attribute's value to a variable or method invocation in the parent's script file (for example, alertString = alertTitle). Communication from the parent to the child is quite straightforward.

But for reusable components to be truly versatile, there must also be a mechanism for the child component to interact with the parent, either by setting the parent's variables or invoking its methods, or both. This mechanism must be flexible enough that a given child component can be reused by various parent components without having to be modified in any way. WebObjects provides just such a mechanism, as illustrated by the following example.

Table of Contents Next Section