Saturday 1 December 2007

How to use decorator WAFormDecoration

This is a very simple example of how to use a decorator in Seaside, based on my understanding from two blogs. A decorator allows you to wrap standard functionality around the content generated by your component, so hiding a lot of the 'boilerplate' complexity otherwise required. This example allows you to build up a form with buttons of your choice; provide a list of buttons, and a matching method for each.

You need to ensure that you have a very recent (533 or later) version of Seaside for the defaultButton behaviour to take effect correctly. If you're using multiple decorators, don't forget to make the FormDecoration the last one you apply.

WAComponent subclass: #SimpleTestForm
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Sample'

initialize
| form |
super initialize.
form := WAFormDecoration new buttons: self buttons.
self addDecoration: form.

buttons
^ #(okay cancel)

okay
"your action goes here"
self inform: 'you pressed okay'

cancel
"your action goes here"
self inform: 'you cancelled'

defaultButton
^ self buttons first


renderContentOn: html
"usual form contents go here"
html textInput.
html text: 'asd'
"etc"

No comments: