Skip to content
Tutorials Center
My learning

Topics

Lesson 31 of 38 ยท Web and Applications

Seaside: Web Components and Callbacks

Learn how Seaside builds web applications as Smalltalk objects: components, renderOn:, the canvas, callbacks, call and answer flow, and sessions. Real code is read-only; a runnable JavaScript stand-in shows the model.

Most web frameworks route a URL to a handler and ask you to carry state through forms, cookies and sessions by hand. Seaside takes a different view: a web application is a set of components, which are ordinary Smalltalk objects that know how to draw themselves. Links and buttons are tied to blocks called callbacks, not to URLs. You write a web page much as you would write a desktop interface, and the framework deals with HTTP.

Seaside is not installed on this site, so the code is read-only. A runnable JavaScript stand-in at the end models the central trick: components that render HTML and callbacks registered under generated keys.

A component

A component is a subclass of WAComponent. Its job is renderContentOn:, which receives an HTML canvas and sends it messages (read-only):

SMALLTALK
WAComponent subclass: #CounterComponent
    instanceVariableNames: 'count'
    package: 'Demo-Web'.

CounterComponent >> initialize
    super initialize.
    count := 0

CounterComponent >> renderContentOn: html
    html heading level: 2; with: 'Counter'.
    html paragraph: 'Current value: ', count printString.
    html anchor
        callback: [ count := count + 1 ];
        with: 'Increase'.
    html space.
    html anchor
        callback: [ count := 0 ];
        with: 'Reset'

There is no template language. The canvas builds the HTML tree with ordinary messages such as heading, paragraph, anchor, form, textInput, select and div. Because the page is built by code, loops, conditionals and reuse work with normal Smalltalk: render a list with do:, extract a method for each section, or nest another component with html render: otherComponent.

Register it as an application:

SMALLTALK
CounterComponent class >> initialize
    (WAAdmin register: self asApplicationAt: 'counter')

Then open /counter in a browser.

Callbacks

When Seaside renders anchor callback: [ ... ], it generates a unique key for the block, stores the block in the session, and writes a link containing that key. A click sends the key back, Seaside finds the block, runs it, and renders the page again. The same applies to form inputs: html textInput on: #name of: self binds the field to the accessor pair, and the value is stored in the object when the form is submitted.

This gives you state kept in objects, not in URLs. The counter above needs no ?count=3 parameter; the component holds count and the callback changes it. Seaside re-renders the whole component after callbacks, so the page stays consistent.

call: and answer:

The feature that surprises newcomers is the modal flow. A component can say self call: anotherComponent. That component replaces it on screen. When the user finishes, the new component says self answer: result and control returns to the first component as if call: were an ordinary method returning a value (read-only):

SMALLTALK
OrderComponent >> confirm
    | ok |
    ok := self call: (ConfirmDialog message: 'Place the order?').
    ok ifTrue: [ self placeOrder ]

ConfirmDialog >> renderContentOn: html
    html paragraph: message.
    html anchor callback: [ self answer: true ]; with: 'Yes'.
    html space.
    html anchor callback: [ self answer: false ]; with: 'No'

A whole multi-page wizard becomes a single method with local variables and normal control flow. Seaside implements this by saving the Smalltalk stack (continuations, related to the contexts in thisContext and the execution stack) so the method can resume after a click.

Sessions and the back button

Each visitor has a session holding their component tree and registered callbacks. Seaside also snapshots state so the browser's Back button works: the page is bound to a state key, and going back restores that state (for objects registered as backtracking). Sessions expire after a period of inactivity. Because every page holds callbacks in memory, a production deployment sets sensible expiry and limits.

Serving it

Seaside runs on a web server inside the image, typically Zinc, the HTTP library you will use directly in Teapot and Zinc. You start it with a command like ZnZincServerAdaptor startOn: 8080 and put a reverse proxy such as nginx in front for production.

A model you can run

This JavaScript stand-in shows the ideas: a tiny HTML canvas, a component with renderContentOn, callbacks stored under generated keys, and a click simulation that runs the block and re-renders. It prints HTML text instead of serving a real page.

JS Stand-in: components, canvas and callbacks

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Real Seaside keeps old callbacks valid until the session expires or the state is replaced, while this model resets the table on each render to keep the example short.

A call/answer stand-in

JavaScript has no continuations, but async functions give the same shape: await this.call(dialog) pauses a flow until something answers.

JS Stand-in: call and answer with promises

Press Run (or Ctrl + Enter) to see the console output here.

No output.

This stand-in uses top-level await, so the editor must run it as a module. The point is the control flow: the method reads top to bottom even though the user clicks in between.

When to use Seaside

Seaside suits applications with complex interaction and a lot of server-side state, such as admin tools, wizards and configurators. It is less suited to static sites or to large public APIs; use Teapot for those.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a Seaside component implement to draw itself?

    The component receives an HTML canvas and builds the page with messages to it.
  2. 2. How are links and buttons connected to behaviour?

    Each callback block is stored in the session and referenced by a key in the generated link.
  3. 3. What does self call: aComponent do?

    It gives a modal flow where an entire wizard can be a single method.
  4. 4. Where does a counter component keep its count?

    State lives in objects; callbacks change it and the page is re-rendered.

Summary

  • Seaside components are objects with renderContentOn: that build HTML through a canvas.
  • Callback blocks replace routes and parameters; state stays in instance variables.
  • call: and answer: express multi-page flows as ordinary method code.
  • Sessions hold components and callbacks, and the Back button is supported.
  • The Seaside code is read-only; the JavaScript examples are stand-ins.

Next: Teapot and Zinc: HTTP Services