Dynamic Web Development with Seaside

12.6Decorations

Sometimes we would like to reuse a component while adding something to it, such as an information message or extra buttons. Seaside has facilities for doing this. In Seaside parlance, this is called “decorating” a component. Note that this is not implemented using the design pattern of the same name, but rather as a Chain of Responsibility. This means that decorations form a chain of special components into which your component is inserted, and that a given message pass through the chain of decorators.

Decorations can be added to any component by calling WAComponent>>addDecoration:. Decorations are used to change the behavior or the look of the decorated component.

A component decoration is static in the sense that it should not change after the component has been rendered. Thus, a decoration should be attached to a component either just after it (the decorator) is created, or just before the component is passed as argument of a call: message

self call: (aComponent
addDecoration: aDecoration;
yourself)

There are three kinds of decorations:

  • Visual Decorations. These change a visual aspect of the decorated component: WAMessageDecoration renders a heading above the component; WAFormDecoration renders a form with buttons around the component; and WAWindowDecoration renders a border with a close widget around the component.
  • Behavioral Decorations. These allow you to add some common behaviours to your components: WAValidationDecoration allows you to add validation of the answer-argument and the display of an error message.
  • Internal Decorations. These support internal logic that you will use when building complex applications: WADelegation is used to implement the call: message; WAAnswerHandler is used to handle the answer: message.

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.