Dynamic Web Development with Seaside

2.4.2Defining a Component

Now we will define a new component named WebCounter. In Seaside, a “component” refers to any class which inherits from the class WAComponent (either directly or indirectly).

It is only a coincidence that this class has the same name as its package. Normally packages will contain several classes, and the package names and class names are unrelated.

To start creating your class, click on the WebCounter package you just created, to ensure that it is selected. The “class creation template” will appear in the source pane of the browser. Edit this template so that it looks as follows:

WAComponent subclass: #WebCounter
instanceVariableNames: 'count'
classVariableNames: ''
poolDictionaries: ''
category: 'WebCounter'

Notice that lines 3 and 4 contain two consecutive single quote characters, not a double quote character. We are specifying that the WebCounter class is a new subclass of WAComponent. We also specify that this class has one instance variable named count. The other arguments are empty, so we just pass an empty string, indicated by two consecutive quote marks. The “category” value should already match the package name. Note that an orange triangle in the top-right indicates that the code is not compiled yet.

Once you are done entering the class definition, right-click anywhere in that pane to bring up the context menu, and select the menu item Accept (s) as shown in Figure 5. Accept in Smalltalk jargon roughly means compile.

Creating the class WebCounter

Once you have accepted, your browser should look similar to the one shown in Figure 6. The browser now shows the class that you have created in the class pane. Now we are ready to define some behaviour for our component.

The class has been created

Copyright © 21 April 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.