Implement a method
Now that you have declared some variables and you know which elements the variables represent, you need to write a script that uses this information. Specifically, the script needs to take the input from the form elements and add it to the end of the guests array. You do this in the submit method.You may have noticed that when you dragged the form onto the page, the word "submit" appeared in the object browser at the bottom of the window. This represents the submit method. When you create a form with a Submit button, WebObjects Builder creates a submit method for you and binds the button to the method.
- In the Main window, click the script button to display a window containing Main's script file.
- Enter the following line inside the declaration for the submit method:
- Close the script window and save the Main component.
Main's script file appears in a separate window. It contains declarations for the variables and methods listed in Main's object browser, namely aGuest and the submit method. (You don't see the guests array because it's declared in the application script, not the Main component.)
[self.application.guests addObject:aGuest];
A closer look
You just implemented the submit method. When the user clicks the Submit button, the variable aGuest receives the values that the user entered in the form, and the submit method is invoked. This method adds the information contained in aGuest to the end of the application script's guests array. The guests array contains a list of everybody who ever used the GuestBook.To implement this method, you used a language called WebScript. WebScript is the WebObjects scripting language. You can read more about it in "Using WebScript" in the WebObjects Developer's Guide.
Table of Contents Next Section