I'm a learning Smalltalk and developing an application in Seaside.
The first part of the application will be the so called is administration side. In this part I can define/manage items users of the application are allowed to choose from. All items defined will be the same for all users. So I have created a class called sportsController.
I have used a singleton pattern as defined here: smalltalk singleton pattern: how do I initialize the instance variables?.
On the class side I have:
default
^ Default ifNil: [ Default := self new ]
On the instance I have:
initialize
sports := OrderedCollection new.
and
sports
^ sports
When I call the view I have:
manageSports
view := SportsAdminView new model: SportsController default
The method 'manageSports' is called as a callback. When I run the view the following code is executed:
renderContentOn: html
html anchor
callback: [self addSport];
with: 'Add new sport'.
html
unorderedList: [self model sports
do: [:value | html
listItem: [self renderSport: value on: html]]].
When I run this #sports is nil. So there is a MessageNotUnderstood notification. So I'm probably doing something wrong; what? That said is there a better way of doing this? The main objective is to create class that used by all sessions a like.
BTW For the moment I don't do persistence yet, other then in the image. 'Real' persistence will be dealt with later. For the moment I need to be able to add data to develop the customer side of the application.
Is it possible that you called SportsController default
the first time before you added the initialize
method to the instance side? In this case your initialize
method was never called.
So you can call it once from the workspace via SportsController default initialize
, or you set the class variable Default
to nil
and try it again.