[Seaside] What's the difference and why??

Brian Brown rbb at techgame.net
Mon Feb 27 21:35:55 UTC 2006


Hi Rick - let's step back for a sec and talk about a different  
structure....

:)

What *I* do, and others may have different patterns for their seaside  
apps, is to create a main page component, and #call: (this is  
Smalltalk notation for denoting a message send, or a method call in C+ 
+ parlance) the components that I want to show up on the page. So, as  
a simple example, you might have an initialize method:

initialize
	mainPage := MainPage new.
	aboutPage := AboutPage new.
	enrollPage := EnrollPage new.
	contactPage := ContactPage new.
	menuArea := MenuArea on: self.

mainPage, aboutPage etc. are instance variables on your main App  
class - say MyWebApp, where the initialize is located.


Then, in MyWebApp>>renderContentOn:

renderContentOn: html
	html divClass: 'sidebar' with: [html render: menuArea].
	html divClass: 'contentarea' with: [html render: mainPage].

Then in MenuArea class, you would have a class side method like:

on: aComponent
	^ (self new) parent: aComponent

... back on the instance side (a setter for parent):
parent: aComponent
	parent := aComponent

(parent being an instance var)

parent
	^ parent

and then:

renderContentOn: html
	html unorderedList: [
        	html listItem: [html anchorWithAction: [self parent  
clearAllDelegates] text: 'Home'.].
        	html listItem: [html anchorWithAction: [self parent mainPage  
call: self parent aboutPage] text: 'About'.].
       	html listItem: [html anchorWithAction: [self mainPage call:  
self parent call enrollPage] text: 'Enroll'.].
        	html listItem: [html anchorWithAction: [self mainPage call:  
self parent call contactPage] text: 'Contact Us'.].
    ].

This means that you have to have accessor method for the instance  
variables that get initialized on the MyWebApp class so that you can  
call "self parent enrollPage" from the MenuArea component. You could  
also create convenience methods on your menu page, like:

enrollPage
	^ self parent enrollPage


Anyway, I hope this gives you a different idea of how you can do some  
things. Feel free to ask any other questions!

Brian

On Feb 24, 2006, at 10:35 PM, Rick Flower wrote:

> I'm trying to find out why I need to write the method below using  
> one of the two ways below:
>
> generateMainPageLinks: html
>    html unorderedList: [
>        html listItem: [html anchorWithAction: [self renderMain:  
> html] text: 'Home'.].
>        html listItem: [html anchorWithAction: [self renderAbout:  
> html] text: 'About'.].
>        html listItem: [html anchorWithAction: [self renderEnroll:  
> html] text: 'Enroll'.].
>        html listItem: [html anchorWithAction: [self  
> renderContactUs: html] text: 'Contact Us'.].
>    ].
>
>
> generateMainPageLinks
>    self html unorderedList: [
>        self html listItem: [self html anchorWithAction: [self  
> renderMain: self html] text: 'Home'.].
>        self html listItem: [self html anchorWithAction: [self  
> renderAbout: self html] text: 'About'.].
>        self html listItem: [self html anchorWithAction: [self  
> renderEnroll: self html] text: 'Enroll'.].
>        self html listItem: [self html anchorWithAction: [self  
> renderContactUs: self html] text: 'Contact Us'.].
>    ].
>
> Now, since I'm not passing in any arguments to this method (at  
> least for now), I'm wondering why I need to specify "html" on the  
> first
> version of the code (and have the ":").. On the second one, if I  
> don't put the "self" in front of the various "html" items, I get  
> compilation errors
> saying it doesn't know what they are..  I'm sure it's one of those  
> fundamental SmallTalk things I'm missing here, but this one beyond  
> me..
>
> Now, before you get too carried away, I've NOT tried running this  
> code on the bottom, but have run with the top one.  Any
> insight as to what I'm missing would be greatly appreciated!
>
> -- Rick
>
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the Seaside mailing list