To illustrate that mechanism, let’s use the
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
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
self call: (ContactView new
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 ];
callback: [ self removeContact: aContact ];
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
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.