Clearing the Guest List
While developing your application, you may find it useful to be able to remove all guests from the list. (Typically, you wouldn't allow users to remove all guests from the list.)
- In WebObjects Builder, make the GuestList component window active.
- Choose Add Action from the pull-down menu at the bottom of the window. In the panel, enter clearGuestList as the name of the action and set the page returned to nil.
- Choose View Source File from the pull-down menu.
- Enter the following code before the return statement in clearGuestList:
- Save GuestList.wos.
- Go back to WebObjects Builder.
- Place the cursor below the table and press Enter.
- Choose from the Elements pop-up list and click .
- Using the Inspector, bind the submit button's value attribute to (including the quotes) "Clear Guest List".
- Bind the action attribute to clearGuestList.
Project Builder displays the code for GuestList.wos. You'll notice that there is a skeleton of the clearGuestList action method, using WebScript syntax, as well as the declaration for currentGuest that you created previously.
[[self application] clearGuests];
This code calls the application's clearGuests method, which removes all the Guest objects from the array.
This creates a submit button that the user will click to clear the guest list.
This changes the title of the button. Note that the quotes are necessary to indicate that you're binding a string, not a variable.
When the user clicks the button, the clearGuestList action method is called, which causes the guest list to be cleared and the page to be redrawn.
Table of Contents Next Section