Documentation Archive Developer
Search
PATH  WebObjects 4.0 Documentation > Getting Started With WebObjects

Table of Contents Previous Section

Using a Repetition

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 (an instance of the WORepetition class). 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.

  1. In WebObjects Builder, make the Main component window active (double-click Main.wo).

  2. Select the table at the bottom of the page by clicking outside it and dragging across it.

  3. Choose Edit Copy.

  4. Make the GuestList component active.

  5. Place the cursor at the bottom of the page and choose Edit Paste.

    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.

  6. 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, and click Add.

  7. Choose from the Elements pop-up list to display the Tables buttons.

  8. Click somewhere in the table, then click in the toolbar to enter structure-editing mode. (Alternatively, Control-click on the table.)

  9. Click one of the triangles in the second row to select the entire row.

  10. Choose to display Other WebObjects in the toolbar and click

    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.

  11. In the object browser, select application in the first column.

  12. In the second column, make a connection from allGuests to the entire row (not a WOString in a cell).

    The Inspector window for that element opens. To display the WORepetition bindings click on the icon at the top of the inspector. The list attribute is selected by default.

  13. Click Connect to bind application.allGuests to the list attribute.

  14. Bind currentGuest to the repetition's item attribute.

    As a short cut, 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.

  15. Save the GuestList component.

  16. Delete the table from the Main component, since you no longer need it.

  17. Build and launch your application.

  18. Test your application by entering data for multiple guests and verifying that each guest appears in the table.

Table of Contents Next Section