WAMessageDecoration renders a heading above the component using the message
WAComponent>>addMessage:. As an example we add a message to the
ContactView component by sending it
addMessage:, see Figure 89.
editor := ContactView new.
editor contact: self contacts first.
editor addMessage: 'Editing...'. " <-- added "
editor onAnswer: [ :answer | self inform: 'Saved', answer printString ]
Note that the
WAComponent>>addMessage: returns the decoration, so you may want to also use the
yourself message if you need to refer to the component itself:
html render: (AnotherComponent new addMessage: 'Another Component'; yourself)
The following example adds a window decoration to the
ContactView component. To see it in action, use the contacts application implemented by the
ContactList component (probably at http://localhost:8080/contacts. The result of clicking on an edit link is shown in Figure 90.
self addDecoration: (WAFormDecoration new buttons: #(cancel save)).
self addDecoration: (WAWindowDecoration new title: 'Zork Contacts')
You may see that your Save and Cancel buttons are duplicated: you can remove this duplication by commenting out the
self renderSaveOn: html line from
It is much more common to add a window decoration when calling a component rather than when initializing it. The following example illustrates a common idiom that Seaside programmers use to decorate a component when calling it. It uses a decoration to open a component on a new page.
"Replace the current page with aComponent."
addDecoration: (WAWindowDecoration new
cssClass: self cssClass;
title: self label;
Form Decoration. A
WAFormDecoration places its component inside an HTML form tag. The message
WAFormDecoration>>buttons: should be used to specify the buttons of the form. The button specification is a list of strings or symbols where each string/symbol is the label (first letter capitalized) for a button and the name of the component callback method when button is pressed.
The component that a
WAFormDecoration decorates must implement the method
WAFormDecoration>>defaultButton, which returns the string/symbol of the default button (the one selected by default) of the form. For each string/symbol specified by the
WAFormDecoration>>buttons: method, the decorated component must implement a method of the same name, which is called when the button is selected.
Be sure not to place any decorators between
WAFormDecoration and its component, otherwise the
defaultButton message may fail.
form := WAFormDecoration new buttons: self buttons.
self addDecoration: form
Using Decorations in the Contacts application. You can add a
ContactView as follows: define an
initialize method to add the decoration, and remove the superfluous rendering calls from
renderContentOn:, to leave simpler code and an unchanged application (see Figure 91).
self addDecoration: (WAFormDecoration new buttons: #(cancel save))
self renderNameOn: html.
self renderEmailOn: html.
self renderGenderOn: html.
self renderSendUpdatesOn: html.
self renderDateOn: html.
save as our button names since these methods were already defined in the class, but we could have used any names we wanted as long as we implemented the corresponding methods.