Suppose you wanted a component that shows only the name and email of our
ContactView component. There are no special facilities in Seaside for doing this, so you may be tempted to use template methods and specialize hooks in the subclasses. This may lead to the definition of empty methods in subclasses and may force you to define as many subclasses as situations you want to cover, for example if you want to create a
SimpleContactView and a
An alternative approach is to build more advanced components using the messages
perform:with: with a list of method selectors to be sent:
"should be called during action phase"
methods := #(renderNameOn: renderEmailOn:)
methods do: [ :each | self perform: each with: html ]
You can also define a component whose rendering depends on whether it is embedded. Here is an example where the rendering method does not wrap its content in a form tag when the component is in embedded mode (i.e., when it would expect its parent to have already created a form in which to embed this component). A better way of doing this would be to use a
FormDecorator as shown in Section 12.6.
EmbeddableFormComponent>>renderContent: html body: aBlock
ifTrue: [ aBlock value ]
ifFalse: [ html form: aBlock ]
self renderContent: html body: [
"lots of form elements get rendered here"
self renderSaveOn: html ]
This would then be embedded by another component using code like:
html form: [
"some form elements here, followed by our embeddable Component:"
html render: (EmbeddableFormComponent new beEmbedded; yourself) ]
If you need more sophisticated dynamic control over the rendering of your component, you may want to use Magritte with Seaside. Magritte is a framework which allows you to define descriptions for your domain objects. It then uses these descriptions to perform automatic actions (loading, saving, generating SQL...). The Magritte/Seaside integration allows one to automatically generate forms and Seaside components from domain object described with Magritte descriptions, see Chapter 26. Magritte also offers ways to construct different views on the same objects and so the possibility to create multiple varieties of components: either by selecting a subset of fields to display, or by offering read-only or editable components. As such, it is an extremely useful addition to plain Seaside.