. .


ST 4U 131: Static Urls in Seaside

September 12, 2011 6:41:45.707

Today's Smalltalk 4 You continues the VA Smalltalk Seaside tutorial with a look at static urls - how to add them to your Seaside application. Turns out it's pretty easy. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Static Urls.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll look at static urls - something that most websites need (at least at the entry points), and that Seaside does not provide by default. That doesn't mean it's hard to do though - you simply have to tell your application which urls you'll be handling yourself. To do that, you need to create an #initialRequest: method in your entry point class - BlogServerView in our case:

initialRequest: aRequest
  "set up for handling static urls"

  super initialRequest: aRequest.
  aRequest at: 'id' ifPresent: [:idNumber |
    | postOrNil |
    postOrNil := BlogStorage default posts 
	detect: [:each | each id printString = idNumber]
	ifNone: [nil].
    postOrNil ifNotNil: [listComponent filterBlock: [Array with: postOrNil]]].

There are a few things going on there. First off, we get the request sent to us, along with the arguments in an easy to handle fashion - using Dictionary protocol with the url argument as the key. The above code assumes that our urls will look something like this:


Where the id number is associated with each post object. That also assumes that each post as a "perm-link" associated with it - which we'll set up on the post title's as they render - in BlogListView, we'll modify #renderPostOn: to call #renderTitleOn:for:, instead of just directly dropping out the title as text. Then we'll need that method::

renderTitleOn: html for: post
  "put a permalink on the title"

  html strong: [ (html anchor)
	url: 'blogView?id=', post id printString;
	with: post title].

That sets up the post titles to have the urls we are looking for in the #initialRequest: method. If it all works, we can now refresh our top page, and click on a post - you should see one post come back, something like this:

One Post

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , , ,

[st4u131-iPhone.m4v ( Size: 4500669 )]

posted by James Robertson

 Share Tweet This