Intercomponent communication – Apple WebObjects 3.5 User Manual

Page 98

Advertising
background image

Chapter 6

Creating Reusable Components

98

the

alertTitle

and

infoString

attributes (leaving the other attributes private) using this

AlertPanel.api

file:

Required = (alertTitle, infoString);
Optional = ();

See the WebObjects Tools and Techniques online book for more information.

AlertPanel is one of several components included in a sample application called
ReusableComponents. This application demonstrates and documents how to
create and use reusable components. If you look at the source code for
AlertPanel, you’ll notice that it’s moderately complicated and, in fact, relies on
other reusable components for its implementation. However, WebObjects lets
you think of the AlertPanel component as a black box. You simply position the
component in your HTML template, specify its attributes in the declarations
file, and implement any associated dynamic behavior in your code.

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 shown in Figure 28, 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 component’s attributes is set either statically (to a
constant value) or dynamically (by binding the attribute’s value to a variable or
method invocation in the parent’s code). Communication from the parent to the
child is quite straightforward.

Advertising