Table of Contents Previous Section 

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 
  2. The repetition appears in the component window.

     

  3. Add elements inside the repetition (replacing the word "Repetition"). 
  4. A repetition can contain any other elements, either static HTML or dynamic WebObjects elements.

     

  5. 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.

 When you drag an item from the object browser to the WORepetition to bind it, the default attribute shown in the Inspector depends on whether the item is an array. If it is, list is the default attribute; otherwise, item is the default attribute.

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. Instead, a blue border appears around the row. To bind the repetition, drag from the object browser to anywhere in the row (but not to a dynamic element inside the row). The Inspector 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).

 

Table of Contents Next Section