Dynamic Web Development with Seaside

12.4Intercepting a Subcomponent’s Answer

Components may be designed to support both standalone and embedded use. Such components often produce answers (send self answer:) in response to user actions. When the component is standalone the answer is returned to the caller, but if the component is embedded the answer is ignored unless the parent component arranges to intercept it. In our example application the editor provides an answer when the user presses the “Save” button (i.e. in ContactView>>save) but this answer is ignored. It is easy to change our application to make use of this information; let’s say we want to give the user confirmation that their data was saved. To accomplish this, change IAddress>>initialize and add the WAComponent>>onAnswer: behaviour:

IAddress>>initialize
super initialize.
editor := ContactView new.
editor contact: self contacts first.
editor onAnswer: [ :answer | self inform: 'Saved' ] " <-- added "

Now restart your application (press “New Session”) and try it out. When you press the save button in the editor you should get a dialog tersely notifying you that your data is saved. Note that the component answer is passed into the block (although we didn’t use it in this example).

The onAnswer: method is an important protocol for handling components and their answer.

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.