With WebObjects, you design pages from static HTML elements and dynamic WebObjects elements. The HTML template for a page shows how these features are intermixed:
<CENTER>
<STRONG>Today's image:</STRONG>
<WEBOBJECT NAME=IMAGE></WEBOBJECT>
</CENTER>
<WEBOBJECT NAME=FOOTER></WEBOBJECT>
The portions of the page marked by the WEBOBJECT tags derive their HTML values dynamically. When this page is requested, WebObjects consults the template's corresponding declarations file:
IMAGE : WOImage {src = todaysImage;};
FOOTER : Footer {date = now;};
The first declaration indicates that IMAGE is a WOImage that derives its image data from the invocation of the method todaysImage. WOImage is one of the fundamental dynamic elements that WebObjects defines. The declaration for FOOTER specifies an element that isn't one of WebObjects' fundamental types--it specifies a reusable component.The Footer reusable component is stored in a directory (named "Footer.wo") that contains the same configuration of three files (template, declarations, and script files) as you would find for a WebObjects page. Here's what these files contain:
<WEBOBJECT NAME="DATE"></WEBOBJECT><BR>
DATE:WOString {value = formattedDate;};
id date;
- formattedDate {
id head, tail;
head = [date descriptionWithCalendarFormat:@"%m-%d-%Y"];
tail = [date descriptionWithCalendarFormat:@"%H:%M:%S"];
return [NSString stringWithFormat:@"%@ - %@\n", head, tail];
}
As you can see, the Footer component is simply a string whose contents is dynamically set to be the current date and time.