#call: #answer / sessions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

#call: #answer / sessions

Ramiro Diaz Trepat
I have a couple of basic questions

1)
Is it OK to #call components that never #answer ?  For instance if you
have a page with a menu that #calls components for each of its menu
items, and the user may do this again before the component #answer.
I believe this is the case, for instance, on the Sushi Store, where a
user can be adding sushi to the cart and click on the Browse link on
the menu bar, which will #call the browsing component again, before
answering.
The question is: Will this generate a memory leak ?  Will all those
compoenents add up ? Or is this the proper way to do it?

I'm asking because I am developing my first real basic, but comertial
application in Seaside, and I have not cached up with it real well
yet.
I have a very simple page, with a header, a navigation bar and a main
area, very similar to the Sushi Store.  But I have a WAComponent for
each of those (header, navbar, etc.), placed an the page using divs.
The component of the navication bar, simply shows some options that
when clicked, #call the proper component to be displayed on the main
area.  What I have to do for the component to be displayed on the main
area is calling the #call method from the previous component that is
on the main area, otherwise this newly selected component will be
displayed on the navigation bar DIV.
Is this the proper way to build a basic web app that displays a
specific component for whatever is clicked on the navigation bar?


2)
When you develop a login process, like the one in Ramon's blog.  Where
is it proper to store the user that is logged on? Is this supposed to
be stored somewhere in the WASession?
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: #call: #answer / sessions

Ramon Leon-5
> I have a couple of basic questions
>
> 1)
> Is it OK to #call components that never #answer ?  For
> instance if you have a page with a menu that #calls
> components for each of its menu items, and the user may do
> this again before the component #answer.
> I believe this is the case, for instance, on the Sushi Store,
> where a user can be adding sushi to the cart and click on the
> Browse link on the menu bar, which will #call the browsing
> component again, before answering.
> The question is: Will this generate a memory leak ?  Will all
> those compoenents add up ? Or is this the proper way to do it?

Yes, it's ok.  It might help if you think of #call: as simply display this
component instead of this other component.  A component doesn't have to
answer, nor are you always interested in its answer.

self call: Component new

Replaces self with a new component, whereas if you simply wanted to render a
component without replacing it in the UI, you'd

html render: self someComponent

In the render method of the outer component.

>
> I'm asking because I am developing my first real basic, but
> comertial application in Seaside, and I have not cached up
> with it real well yet.
> I have a very simple page, with a header, a navigation bar
> and a main area, very similar to the Sushi Store.  But I have
> a WAComponent for each of those (header, navbar, etc.),
> placed an the page using divs.
> The component of the navication bar, simply shows some
> options that when clicked, #call the proper component to be
> displayed on the main area.  What I have to do for the
> component to be displayed on the main area is calling the
> #call method from the previous component that is on the main
> area, otherwise this newly selected component will be
> displayed on the navigation bar DIV.
> Is this the proper way to build a basic web app that displays
> a specific component for whatever is clicked on the navigation bar?

Yes, this is correct.  I like to have a currentComponent in a layout like
this, and simply have the menus say

currentComponent call: SomeNewComponent new.

>From the outer container, which acts like a mediator controlling what item
is displayed.  Expect the component to get garbage collected after it's no
longer displayed since you're not holding onto a reference.  If you want to
reuse existing components rather than creating them on each invocation, you
could do...

currentComponent call: (self componentFor: SomeNewComponent)

componentFor: aComponent
  ^components at: aComponent ifAbsentPut:[aComponent new]

And use the components class as a key into a dictionary so you can reuse the
same instance each time they click that menu item.  Since you're holding a
reference to it, it won't be gc'd just because it's not displayed and you
can use the original instance over and over, meaning it'll maintain any
state it previously held, a sometimes very useful and unexpected thing in a
web application.

> 2)
> When you develop a login process, like the one in Ramon's
> blog.  Where is it proper to store the user that is logged
> on? Is this supposed to be stored somewhere in the WASession?

Yes, a custom session class is a good place for this, so you can have access
to it from every component with a simple..

self session currentUser

Also common is

self session database

Ramon Leon
http://onsmalltalk.com


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: #call: #answer / sessions

Ramiro Diaz Trepat
> > When you develop a login process, like the one in Ramon's
> > blog.  Where is it proper to store the user that is logged
> > on? Is this supposed to be stored somewhere in the WASession?
>
> Yes, a custom session class is a good place for this, so you can have access
> to it from every component with a simple..
>
> self session currentUser
>
> Also common is
>
> self session database

If I create a subclass of WASession with the currentUser attribute,
how do I inform Seaside to use it when I call self session? For it not
to pass me a regular WASession
Thank you very much for answering Ramón.
By the way, the work you have been doing with onsmalltalk.com is
great, particularly for noobs like me.
Bye
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: #call: #answer / sessions

Ramon Leon-4
> If I create a subclass of WASession with the currentUser attribute,
> how do I inform Seaside to use it when I call self session? For it not
> to pass me a regular WASession
> Thank you very much for answering Ramón.
> By the way, the work you have been doing with onsmalltalk.com is
> great, particularly for noobs like me.
> Bye

Thanks, and you simply setup your session class as the session component
on the application configuration page in the web browser where you setup
and configure the app, /seaside/config then configure on your app.

Ramon Leon
http://onsmalltalk.com

_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: #call: #answer / sessions

Bany, Michel
In reply to this post by Ramiro Diaz Trepat
Found at http://localhost:8080/seaside/faq (SeasideFAQ package)

Subclassing WASession

It is sometimes necessary to subclass WASession. Typical situations for subclassing WASession.

- Need to clean-up external resources when Seaside session expires (reimplement #unregistered)
- Need to attach some data to the Seaside session using additional instance variables
- Need to include additional behavior, statistics, monitoring (reimplement #responseForRequest:)

Seaside applications are assigned their session class using the "config" application ("Session Class" field).
It can also be set programmatically

    app preferenceAt: #sessionClass put: MySession




> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf
> Of Ramiro Diaz Trepat
> Sent: vendredi, 19. janvier 2007 03:28
> To: The Squeak Enterprise Aubergines Server - general discussion.
> Subject: Re: [Seaside] #call: #answer / sessions
>
> > > When you develop a login process, like the one in Ramon's blog.  
> > > Where is it proper to store the user that is logged on? Is this
> > > supposed to be stored somewhere in the WASession?
> >
> > Yes, a custom session class is a good place for this, so
> you can have
> > access to it from every component with a simple..
> >
> > self session currentUser
> >
> > Also common is
> >
> > self session database
>
> If I create a subclass of WASession with the currentUser
> attribute, how do I inform Seaside to use it when I call self
> session? For it not to pass me a regular WASession Thank you
> very much for answering Ramón.
> By the way, the work you have been doing with onsmalltalk.com
> is great, particularly for noobs like me.
> Bye
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: #call: #answer / sessions

Ramiro Diaz Trepat
It's great that you guys did that package, I have already installed
it.  I did't know about it.
It probably shoud be installed by default, together with the examples
like the Sushi Store.  And also removed with the "WADispatcher default
trimForDeployment." that I have just learned :)




On 1/19/07, Bany, Michel <[hidden email]> wrote:

> Found at http://localhost:8080/seaside/faq (SeasideFAQ package)
>
> Subclassing WASession
>
> It is sometimes necessary to subclass WASession. Typical situations for subclassing WASession.
>
> - Need to clean-up external resources when Seaside session expires (reimplement #unregistered)
> - Need to attach some data to the Seaside session using additional instance variables
> - Need to include additional behavior, statistics, monitoring (reimplement #responseForRequest:)
>
> Seaside applications are assigned their session class using the "config" application ("Session Class" field).
> It can also be set programmatically
>
>     app preferenceAt: #sessionClass put: MySession
>
>
>
>
> > -----Original Message-----
> > From: [hidden email]
> > [mailto:[hidden email]] On Behalf
> > Of Ramiro Diaz Trepat
> > Sent: vendredi, 19. janvier 2007 03:28
> > To: The Squeak Enterprise Aubergines Server - general discussion.
> > Subject: Re: [Seaside] #call: #answer / sessions
> >
> > > > When you develop a login process, like the one in Ramon's blog.
> > > > Where is it proper to store the user that is logged on? Is this
> > > > supposed to be stored somewhere in the WASession?
> > >
> > > Yes, a custom session class is a good place for this, so
> > you can have
> > > access to it from every component with a simple..
> > >
> > > self session currentUser
> > >
> > > Also common is
> > >
> > > self session database
> >
> > If I create a subclass of WASession with the currentUser
> > attribute, how do I inform Seaside to use it when I call self
> > session? For it not to pass me a regular WASession Thank you
> > very much for answering Ramón.
> > By the way, the work you have been doing with onsmalltalk.com
> > is great, particularly for noobs like me.
> > Bye
> > _______________________________________________
> > Seaside mailing list
> > [hidden email]
> > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> >
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: #call: #answer / sessions

Ramiro Diaz Trepat
In reply to this post by Ramon Leon-5
Hello Ramón,
    I implemented this component Dictionary that you told me about in
the mail below.  This method would recycle component instances instead
of creating a new one every time.
    The problem is that when I #call: an already used instance, my
Squeak image starts consuming resources rapidly and indeed it hangs in
about 5 seconds.
    I have tried this with very simple classes, like a WAComponent
subclass that renders "hello" and another  that renders "goodbye" and
always presents the same behaviour (Mac and LInux VMs).   But it works
perfectly if I create a new instance every time tough.
    I'm sure I must be doing something wrong...

In the main component's rendering method, I have anchors like this:

html anchor callback: [self dispatch: HelloComponent ]; with: 'Hello'.
html anchor callback: [self dispatch: GoodbyeComponent ]; with: 'Goodbye'.

then:

#dispatch: activeComponentClass
        | tmpComp |
        tmpComp := currentComponent.
        currentComponent := self componentFor: activeComponentClass.
        tmpComp call: currentComponent.

and the #componentFor: method is exactly as you wrote it.

Do you see anything wrong?
Thanks


r.



PS: nobody answers my questions about using a reverse proxy with a
seaside app :(






On 1/18/07, Ramon Leon <[hidden email]> wrote:
<snip>

> >
> > I'm asking because I am developing my first real basic, but
> > comertial application in Seaside, and I have not cached up
> > with it real well yet.
> > I have a very simple page, with a header, a navigation bar
> > and a main area, very similar to the Sushi Store.  But I have
> > a WAComponent for each of those (header, navbar, etc.),
> > placed an the page using divs.
> > The component of the navication bar, simply shows some
> > options that when clicked, #call the proper component to be
> > displayed on the main area.  What I have to do for the
> > component to be displayed on the main area is calling the
> > #call method from the previous component that is on the main
> > area, otherwise this newly selected component will be
> > displayed on the navigation bar DIV.
> > Is this the proper way to build a basic web app that displays
> > a specific component for whatever is clicked on the navigation bar?
>
> Yes, this is correct.  I like to have a currentComponent in a layout like
> this, and simply have the menus say
>
> currentComponent call: SomeNewComponent new.
>
> >From the outer container, which acts like a mediator controlling what item
> is displayed.  Expect the component to get garbage collected after it's no
> longer displayed since you're not holding onto a reference.  If you want to
> reuse existing components rather than creating them on each invocation, you
> could do...
>
> currentComponent call: (self componentFor: SomeNewComponent)
>
> componentFor: aComponent
>   ^components at: aComponent ifAbsentPut:[aComponent new]
>
> And use the components class as a key into a dictionary so you can reuse the
> same instance each time they click that menu item.  Since you're holding a
> reference to it, it won't be gc'd just because it's not displayed and you
> can use the original instance over and over, meaning it'll maintain any
> state it previously held, a sometimes very useful and unexpected thing in a
> web application.
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside