Apple WebObjects 3.5 User Manual

Page 99

Advertising
background image

Intercomponent Communication

99

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.

Consider an AlertPanel component like the one described above, but with
the added ability to accept user input and relay that input to a parent
component. The panel might look like the one in Figure 29.

Figure 29. An Alert Panel That Allows User Input

As in the earlier example, you use this component by simply declaring its
position within the HTML page:

Parent's Template File

<HTML>
<HEAD>

<TITLE>Alert</TITLE>

</HEAD>
<BODY>

<WEBOBJECT NAME = "ALERT"></WEBOBJECT>

</BODY>
</HTML>

The corresponding declarations file reveals two new attributes (indicated in
bold):

Parent's Declarations File (excerpt)

ALERT: AlertPanel {

infoString = message;
infoFontSize = 4;
infoFontColor = "#500000";
alertString = "New Release";
alertFontColor = "#A00000";
alertFontSize = 6;
tableWidth = "50%";
parentAction = "respondToAlert";
exitStatus = usersChoice;

};

Advertising