There’s something about Seaside’s URLs that has bothered me for a long time, and I just discovered a solution. I haven’t seen anything about this anywhere else, so I figured I’d write it down in case it’s useful to anyone else.
Since your URLs are managed by your Seaside session, they all become invalid when your session times out. Leave your browser alone for a while, then return and click a link. Instead of taking you where it said it would, the link ends up taking you back to the first page of the app.
The well-known pattern for creating “bookmarkable URLs” is part of the solution here. You override #updateUrl: in your component, and then you override #initialRequest: in your root component or one of its children (i.e. something that’s visible by default). However, that only solves the problem of returning to your current page and has nothing to do with meaningful links on your current page after your session expires.
For most applications, this sort of behavior is not a big deal. Your session times out, you click something, and you’re kicked back to the “please sign in” page. Users tolerate this, because they’re used to the idea that their computer shouldn’t stay signed in forever.
But on a public area of a site, this sort of behavior really can get frustrating. I often pull up a page, get interrupted, and don’t get back to the page for several hours or days. The SqueakSource site has done this to me more than once. Browse to a SqueakSource page, go have lunch, and then come back and click a link. You get shown the homepage instead. Argh!
Thankfully, there are hooks in Seaside that make meaningful links possible. But they’re not very well known, and I can’t find any reference to them anywhere online. The methods are on WAAnchorTag, named #extraPath: and #extraParameters:. These two methods allow you to mangle the URL on the front side, just like you can with #updateUrl: on the other end.
You can use them like this:
(html anchor)
callback: [self registerVolunteer];
extraPath: 'volunteer';
with: 'Become a Volunteer!'
If you’re already using the hooks for bookmarkable URLs, then it’s simply a matter of putting in the right path or parameters when you build the link.
It’s entirely possible to build meaningful URLs in Seaside. The tools are all there. And even though it seems harder than in other frameworks, it’s really not. It just feels hard, because Seaside gives you such a nice abstraction the rest of the time.
And if you’re building a content management system, you’ll likely be creating an abstraction that hides these details anyway.
11 Comments
June 28, 2007 at 3:21 pm
I’m glad to know that I wasn’t the only one who was frustrated whenever SqueakSource kicked me out to the main page.
June 28, 2007 at 10:36 pm
You know, it’s fairly simple to rig up a generic Ajax callback in your component base class that polls the server just under the timeout to prevent a session from ever expiring should someone leave the browser sitting. Just another way to avoid this problem. Nice find though.
June 29, 2007 at 5:56 am
Ramon — that won’t really work, I’m afraid. One very typical case is folks shutting the lid on their macs for a few hours, and then opening them again. No AJAX while suspended I’m afraid.
June 29, 2007 at 7:58 am
Well, the timeout is configured on server-side. Server should allow user’s session to linger for days or weeks, so – no timeouts.
June 29, 2007 at 1:46 pm
The problem with SqueakSource is not that we don’t know about these hooks, the problem is that it’s based on an old version of Seaside that doesn’t have them. In fact many of them were introduced as a result of SqueakSource. The reason why we aggressively time out sessions at SqueakSource is because we had several stability problems with the VM.
June 30, 2007 at 8:10 am
@Brock, good point, I hadn’t considered suspend.
August 28, 2007 at 12:58 am
[...] le problème de la validité des liens après l’expiration de la session, je vous recommande cet article de Ken [...]
October 10, 2007 at 11:06 am
[...] le problème de la validité des liens après l’expiration de la session, je vous recommande cet article de Ken [...]
January 22, 2008 at 11:08 am
[...] Jump to Comments When a Seaside session expires, many of its links become invalid. Sure, you can use the hooks to make certain URLs bookmarkable, but most URLs are session-specific out of necessity. When you click on one after the session [...]
June 25, 2008 at 7:33 pm
Is there an example of an application that uses all of these methods? Or an example code snippet somewhere?
June 20, 2009 at 12:56 pm
My friend on Orkut shared this link and I’m not dissapointed at all that I came to your blog.
p.s. Year One is already on the Internet and you can watch it for free.