Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > Tools and Techniques

   

Repetitions

A repetition (WORepetition) is a container element that repeats its contents a certain number of times. It is like a loop in a structured programming language. Repetitions are one of the most important elements in WebObjects, since it is quite common for applications to display repeated data (often from databases) when the amount of data to be displayed isn't known until run time. Typically, a repetition is used to generate items in a list, multiple rows in a table, or multiple tables.

To create a repetition:

  1. Click .

    The repetition appears in the component window.

  2. Add elements inside the repetition (replacing the word "Repetition").

    A repetition can contain any other elements, either static HTML or dynamic WebObjects elements.

  3. Alternatively, you can select existing elements, then click to wrap the repetition around the elements. This is necessary in some cases, such as wrapping a repetition around a table row.

You usually bind two attributes of a repetition: list and item . The list attribute must be bound to an array. WebObjects generates the elements in the repetition once for each item in the array. Each time through the array, the item attribute points to the current array object. Typically, you bind item to a variable and then use that variable in the bindings of the elements inside the repetition.

In addition, as with WOStrings, WebObjects Builder provides a shortcut for binding repetitions so that you don't have to use the Inspector. Drag to the first binding box to bind the list attribute; drag to the second box to bind the item attribute.

When you wrap a repetition around a table row, the repetition symbol doesn't appear by default (although you can turn on table tag rendering in the Editing Preferences panel). Instead, the row appears in blue. To bind the repetition, drag from the object browser to the <WORepetition> element in the path view. The attribute menu appears, allowing you to complete the binding as usual.

Note: You can also wrap a repetition around a single cell in a table. In addition, this same procedure of wrapping a repetition around a table row or cell also works for conditionals (see next section).


© 1999 Apple Computer, Inc. – (Last Updated July 27 99)