Using a Repetition
You have demonstrated the use of a second component. Now you'll create a table to display the entire list of guests in the GuestList component. To do so, you'll use a dynamic element called a repetition (WORepetition). 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 or a browser, multiple rows in a table, or multiple tables.A repetition can contain any other elements, either static HTML or dynamic WebObjects elements. In the GuestList component, you'll create a repetition that contains a table row.
You'll bind the allGuests array to the WORepetition's list attribute. This tells WebObjects to generate the elements in the repetition once for each item in the array. Each time WebObjects iterates through the array, it sets the repetition's item attribute to the current array object. You bind item to the variable currentGuest and use currentGuest's fields to bind the elements inside the repetition (such as WOStrings). At run time, the table will consist of one row (displaying name, e-mail address, and comments) for each guest.
- In WebObjects Builder, make the Main component window active.
- Select the table at the bottom of the page by clicking outside it and dragging across it.
- Choose Edit Copy.
- Make the GuestList component active.
- Place the cursor at the bottom of the page and choose Edit Paste.
- From the pull-down menu at the bottom of the window, choose Add Variable/Method. Enter currentGuest as the name of the variable and Guest as its type.
- Choose from the Elements pop-up list to display the Tables buttons.
- Click somewhere in the table, then click in the toolbar to enter structure-editing mode. (Alternatively, Control-click on the table.)
- Click one of the triangles in the second row to select the entire row.
- Choose to display Other WebObjects in the toolbar and click
- In the object browser, select application in the first column.
- In the second column, click allGuests and drag the cursor to anywhere inside the row (but not inside one of the WOStrings).
- Click Connect Variable to bind application.allGuests to the list attribute.
- Bind currentGuest to the repetition's item attribute.
- Save the GuestList component.
- Delete the table from Main, since you no longer need it.
- Build and launch your application.
- Test your application by entering data for multiple guests and verifying that each guest appears in the table.
You have just copied the table from Main into GuestList. It has all the same properties, including the bindings. The WOStrings in the table are still bound to instance variables of currentGuest. Since currentGuest is a component variable defined in Main, it isn't accessible from GuestList. Therefore, you need to declare it here.
When you wrap a repetition around a table row in this way, the WORepetition symbol doesn't appear in the table. Instead, a blue border appears around the row. For additional examples of using repetitions, see "Creating a WebObjects Database Application".
The Inspector window opens showing the repetition's bindings. The list attribute is selected by default.
To do this, you can select the row for item, then double-click in the Binding column and type currentGuest.
By using the name currentGuest for the item attribute, you are taking advantage of the fact that the strings in your table are already bound to the fields of currentGuest.
You now have finished implementing the repetition. When the table is generated, it will have one row for each item in the allGuests array.
Table of Contents Next Section