[Seaside] Newbie question

Avi Bryant avi.bryant at gmail.com
Sun Mar 6 16:47:30 CET 2005

On Sun, 6 Mar 2005 10:05:25 -0500, Daniel Salama <dsalama at user.net> wrote:
> This means that for some event generated outside of the application, I
> need to take the user to a particular location in the application with
> the parameters value from the outside world. For example,
> http://demo.seaside.app/process_url?param1=my_name&param2=my_telephone

Hi Daniel,

This is something we'd like to make easier than it is.  However,
here's the awkward way to do it right now:

- create a subclass of WARenderLoopMain.  Like a main() function in a
C program, this is the entry point to your application.
- Override the method #start:. When a user puts in a URL like the one
you mention above, a new session is created and #start: will be called
with a WARequest object.  Extract whatever information you're
interested in from this object.
- Based on the information you have extracted, create and initialize
the component tree for the location in your application that you want
the user to start.
- make a #call: to the root of this new component tree; this will kick
of the usual Seaside render loop and session management from that

So it would look something like this:

MyMainClass>>start: aRequest
  |isbn book bookstore|
  isbn := aRequest at: 'isbn'.
  book := self session lookupByISBN: isbn.
  bookstore := AmazonFrame new contents: (BookListing book: book).
  self call: bookstore

Finally, when configuring your application (at /seaside/config), you
need to override the #mainClass attribute to use MyMainClass instead
of WARenderLoopMain.

> Also, if the user is not logged in
> (session) into the application, can I easily redirect the user to a
> login page and after a successful login, take him/her back to the
> original URL?

There are two subquestions here: one, how to insert a login page into
this process, and two, how to keep the original URL.

Continuing with the above example, you could add a login page just
with another #call:, so,

MyMainClass>>start: aRequest
  |isbn book bookstore user|
  isbn := aRequest at: 'isbn'.
  book := self session lookupByISBN: isbn.
  bookstore := AmazonFrame new contents: (BookListing book: book).
  user := self call: LoginPage new.
  self session user: user.
  self call: bookstore

If you do this, however, once you actually get to the book page the
URL will have changed and the params will be lost.  Rather than
treating this special case, it's better to make sure that all book
pages in your app have the appropriate parameters in their URL.  You
do this by override the #updateUrl: method of your components, in this
case BookListing.  It would look like this:

BookListing>>updateUrl: aUrl
  aUrl addParameter: 'isbn' with: book isbn

Now whenever you have a page that contains that component, the URL
will still have the session ids that Seaside needs, but it will also
have an 'isbn' parameter appended.  As long as the session ids are
valid this extra parameter will be ignored, but if a user bookmarks a
page and goes back once the session has expired, your #start: handler
will get triggered again and get them to the right place.


More information about the Seaside mailing list