Showing posts with label tricks and tips. Show all posts
Showing posts with label tricks and tips. Show all posts

13/10/2008

Creating a framework on top of Seaside

Now that I am starting to understand Seaside (and Squeak), I am beginning to realise that I will probably need to customise a bit. Not because of shortcomings, but rather because there will be various good practices that one will almost always want to build into a project. My previous post about Ramon Leon's initialisation tricks is a good case in point.

Randal's comment on that post - I have included his version in this post - came at the exact moment I happened to be reading another of his entries, which addressed configuring the startup/shutdown issue. So, my default application settings will now contain something like this:


MyClass class >> initialize
self registerAsApplication: #foo.
Smalltalk addToStartUpList: self.
Smalltalk addToShutDownList: self.
self startUp.

MyClass class >> #registerAsApplication: name
^(super registerAsApplication: name)
libraries add: SULibrary;
preferenceAt: #sessionClass put: FooSession;
yourself.

MyClass class >> startUp
self start. "in case I want more things here"

MyClass class >> start

WAKom default.
... other stuff if I want it...
HttpService startOn: 9090 named: 'httpd'.

MyClass class >> shutDown

self stop.

MyClass class >> stop

HttpService allInstancesDo: [:each | each stop. each unregister].

Tips and tricks for making seaside applications easy to manage

One of my current web applications is built on top of Lotus Domino. I have used Domino & Notes for years, and I have a deep respect for it. This particular application was only meant to have a short shelf life, but it has turned into the application that wouldn't die. Normally, I would be happy with that, it is always nice to know that your work is appreciated. However, in this case, because it was put together in a hurry, we didn't build a web based admin console for it. Unfortunately, for us, this means that every time someone want's to use the app, we have to scurry around with a copy of Lotus Notes, messing about with environment variables by hand.
Granted, our 'suffering' is trivial in comparison with people who deal 'real' jobs. After all, as many of my friends have pointed out, all we do is sit around, drinking tea and chatting with people, followed by messing around with computers - hard to argue with that assessment. Anyway, as we move applications over to Seaside, I am really keen that we should do everything possible to simplify the admin. And, that is why I found this section of Ramon Leon's Terse Guide to Seaside, so interesting. He wrote:

FooComponent class>>initialize
"self initialize"
| app |
app := self registerAsApplication: #foo.
app libraries add: SULibrary.
app preferenceAt: #sessionClass put: FooSession

This sets up a dispatcher at /seaside/foo with the Scriptaculous library (SULibrary) and a custom session class that might contain things like the current user or current database session. You can then highlight the comment “self initialize” and run it to create your site. This has the additional advantage of automatically setting up your site in any new image when you load your package into it and also allowing you to programatically recreate your site on demand. This comes in very handy when upgrading to newer versions of Seaside which sometimes require recreating your sites.


I think this is going to be very useful for the future