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
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).
onAnswer: method is an important protocol for handling components and their answer.