Dynamic Web Development with Seaside

11.2Example of call/answer

To illustrate that mechanism, let’s use the ContactListView and ContactView components developed in earlier chapters. Our goal is simple: in a ContactListView component, we will display a link to edit the contacts (as shown in Figure 82), and when the user selects that link, display the ContactView on that Contact. We accomplish this using the call: message.

New version of the ContactListView

The editContact: method is passed a contact as an argument. It creates a ContactView component for the contact and calls this new component by sending it the message call:.

ContactListView>>editContact: aContact
self call: (ContactView new
contact: aContact;
yourself)

Next, we change the method ContactListView>>renderContact:on: to invoke the method we just defined when the edit link is selected, as below:

ContactListView>>renderContact: aContact on: html
html text: aContact name , ' ' , aContact emailAddress.
html text: ' ('.
html anchor " <-- added "
callback: [ self editContact: aContact ];
with: 'edit'.
html space.
html anchor
callback: [ self removeContact: aContact ];
with: 'remove'.
html text: ')'

In the previous chapters, the save method of the ContactView component just displayed the contact values using a dialog. Now, using the message answer, we are able to return control from the newly created ContactView component to the ContactListView which created it and called it. Modify the ContactView so that when the user presses Save it returns to the caller (the ContactListView):

ContactView>>save
self answer

Have a look at the way the method editContact: creates a new instance of ContactView and then passes this instance as an argument to the call: message. When you call a component, you’re passing control to that component. When that component is done (in this case the user pressed the Save button), it will send the message answer to return control to the caller.

Interact with this application now and follow the link. Fill out the resulting form and press the Save button. Notice that you’re back to the ContactListView component. So, you call: another component and when it is done it should answer, returning control of the display to the caller.

You can think of the call/answer pair as the Seaside component equivalent of raising and closing a modal dialog respectively.

Copyright © 19 March 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.