Table of Contents Previous Section

How Server-Side Dynamic Elements Work

To learn how server-side dynamic elements work, look once more at the Main page of the CyberWind example in WebObjects Builder. If you switch over to raw mode, you see that the Main page contains this HTML code in its template:

	Choose between the following menu options:<BR><BR>
	<WEBOBJECT NAME="OPTION_REPETITION">
		<WEBOBJECT NAME="OPTION_LINK">
			<WEBOBJECT NAME="OPTION_NAME"></WEBOBJECT>
		</WEBOBJECT>
	</WEBOBJECT>
Each WEBOBJECT tag denotes the position of a dynamic element. Notice that the tag specifies only where the dynamic element should go; it does not specify the dynamic element's type. The type is specified in the .wod file:

	OPTION_REPETITION:WORepetition {
		list = allOptions;
		item = currentOption
	};
	OPTION_LINK:WOHyperlink {
		action = pickOption
	};
	OPTION_NAME:WOString {
		value = currentOption
	};
In the .wod file, each element is identified by name and then its type is specified. The outermost dynamic element in the HTML file (OPTION_REPETITION) defines a WORepetition, the next element is a WOHyperlink, and the innermost element is a WOString.

Each type specification is followed by a list of attributes. Dynamic elements define several attributes that you bind to different values to configure the element for your application. Usually, you bind attributes to variables or methods from your component's code (see Figure 12).

Figure 12. Dynamic Element Bindings

In the CyberWind example, the Main component binds to two attributes of WORepetition: list and item. The list attribute specifies the list that the WORepetition should iterate over. The item attribute specifies a variable whose value will be updated in each iteration of the list (like an index variable in a for loop). CyberWind's Main component binds the list attribute to an array named allOptions and the item attribute to a variable named currentOption.

The WOHyperlink has an action attribute, which is bound to a method called pickOptions. The action attribute specifies a method that should be invoked when the user clicks the link. In this case, the pickOptions method determines which link the user clicked and then returns the appropriate page.

Finally, the WOString element defines a value attribute, which specifies the string you want displayed. This value attribute is bound to the currentOption variable, which is also bound to the item attribute of the WORepetition. As you'll recall, currentOption is updated with each iteration that the WORepetition makes. So, for each item in the allOptions array (assigned to the WORepetition's list attribute), the WORepetition updates the currentOption variable to point to that item and then the WOString prints it on the page.

Table of Contents Next Section