We already have a working editor component so let's just add it to
our AddressBook component. That is, we're going to embed
the PersonalInformationView2 component inside the
AddressBook component. Here are the steps:
editor) to AddressBook.#initialize method to AddressBook
which creates the editor and gives it a model to edit.#children method to AddressBook
which returns an array containing the editor. This is needed
because Seaside needs to be able to figure out, without rendering,
what components are embedded within your component.#editPerson: so that it just installs the
model in the editor.#renderContentOn: so that it renders the
editorAddressBook after these changes:
WAComponent subclass: #AddressBook instanceVariableNames: 'editor' classVariableNames: '' poolDictionaries: '' category: 'SCSeasideTutorial' initialize editor := PersonalInformationView2 new. editor model: PersonalInformation database first children ^Array with: editor editPerson: person editor model: person people ^PersonalInformation database renderContentOn: html html heading: 'My friends' level: 1. html table: [html tableRow: [html tableHeading: 'Name'. html tableHeading: 'Address'. html tableHeading: 'Birthdate']. self renderDatabaseRowsOn: html]. html hr. html render: editor renderDatabaseRowsOn: html self people do: [:person | html tableRow: [self renderPerson: person on: html]] renderPerson: person on: html html tableData: [html anchorWithAction: [self editPerson: person] text: person name]. html tableData: person address. html tableData: person birthdate mmddyyyy.Try the application...make sure that the editor is doing its job. Activate the halos. You'll notice halos around each of the components. Experiment with the halo buttons to remind yourself what they do. It is very helpful to inspect the state of a component in a running application (or view the rendered HTML).
answer)
in response to user actions. When the component is used standalone
this answer is given back to the caller. If the component is embedded
this answer is ignored unless the parent component arranges to
intercept it. In our example above the editor "answers"
when the users presses save but this answer is ignored. This type of
thing happens quite a bit since components are often usable both
embedded or called. When a component wants to respond to one of its
subcomponents answers, it arranges to do so via the
#onAnswer: method. In the interest of an example, let's
say we want to give the user confirmation that their data was saved.
Change AddressBook>>initialize to:
initialize editor := PersonalInformationView2 new. editor model: PersonalInformation database first. editor onAnswer: [:ans | self inform: 'Saved']Now restart your application (press "New Session") and try it out. Note that the components answer is passed into the block (although we didn't use it in this example).
children method. Either you
are just not correctly instantiating your subcomponent or you are
trying to do something fancy with subcomponents and it isn't working.
Some things to check:
html
render: component for some components? If so, are those
components returned in your children method?