Dynamic Web Development with Seaside

9.6Adding a Contact

We will modify the render method so that we can add a contact to our database, as follows. We add a callback associated with the text ’Add contact’:

ContactListView>>renderContentOn: html
html anchor
callback: [ self addContact ];
with: 'Add contact'.
html unorderedList: [
Contact contacts do: [ :contact |
html listItem: [ self renderContact: contact on: html ] ] ]
| name emailAddress |
name := self request: 'Name'.
emailAddress := self request: 'Email address'.
Contact addContact: (Contact name: name emailAddress: emailAddress)

You should now have the Add contact link as shown in Figure 71.

Contact list with Add contact link

Here we’ve made use of the WAComponent>>request: method to display a message for the user to enter a name, then another message for them to enter an email address. We will discuss the request: method in Part III. Note that a real application would present a form with several fields to be filled up by the user.

Copyright © 20 April 2024 Stéphane Ducasse, Lukas Renggli, C. David Shaffer, Rick Zaccone
This book is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 license.

This book is published using Seaside, Magritte and the Pier book publishing engine.