Apple WebObjects 3.5 User Manual

Page 100

Advertising
background image

Chapter 6

Creating Reusable Components

100

The

parentAction

attribute identifies a callback method, one that the child

component invokes in the parent when the user clicks the Yes or No link. The

exitStatus

attribute identifies a variable that the parent can check to discover which

of the two links was clicked. This attribute passes state information from the
child to the parent. A reusable component can have any number of callback and
state attributes, and they can have any name you choose.

Now let’s look at the revised child component. The template file for the
AlertPanel component has to declare the positions of the added Yes and No
hyperlinks. (Only excerpts of the implementation files are shown here.)

Child's Template File (excerpt)

<TD>

<WEBOBJECT name=NOCHOICE></WEBOBJECT>

</TD>
<TD>

<WEBOBJECT name=YESCHOICE></WEBOBJECT>

</TD>

The corresponding declarations file binds these declarations to scripted
methods:

Child's Declarations File (excerpt)

NOCHOICE: WOHyperlink {

action = rejectChoice;
string = "No";

};

YESCHOICE: WOHyperlink {

action = acceptChoice;
string = "Yes";

};

And the script file contains the implementations of the

rejectChoice

and

acceptChoice

methods:

Child's Script File (excerpt)

id exitStatus;
id parentAction;

- rejectChoice {

exitStatus = NO;
return [self performParentAction:parentAction];

}

- acceptChoice {

exitStatus = YES;
return [self performParentAction:parentAction];

}

Note that

exitStatus

and

parentAction

are simply component variables. Depending on

the method invoked,

exitStatus

can have the values YES or NO. The

parentAction

variable stores the name of the method in the parent component that will be

Advertising