Finding the parent component of a rendered component

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

Finding the parent component of a rendered component

Luke Ivers
If I am using html render: <blah> to render a sub-component of the current
component, is there any way to reference the component who is the
sub-component's parent?

So, I have
ComponentA
  |
  |
  ---ComponentB

And from ComponentB#renderContentOn I want to be able to do something like
parent someFunction
and have that call the function someFunction on whatever component rendered the
current component.

I'm sure there's probably some way to do that, but I don't know what it is.

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

Re: Finding the parent component of a rendered component

Lukas Renggli
> If I am using html render: <blah> to render a sub-component of the current
> component, is there any way to reference the component who is the
> sub-component's parent?
>
> So, I have
> ComponentA
>   |
>   |
>   ---ComponentB
>
> And from ComponentB#renderContentOn I want to be able to do something like
> parent someFunction
> and have that call the function someFunction on whatever component rendered the
> current component.
>
> I'm sure there's probably some way to do that, but I don't know what it is.

Please check the thread "Seaside Components: Parent / Children"

http://lists.squeakfoundation.org/pipermail/seaside/2006-May/007588.html

Cheers,
Lukas

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

Re: Finding the parent component of a rendered component

Luke Ivers
Ok, maybe someone can help me figure out the logic I want here better than what
I have figured out.

I'm making a blog system.  I have the main application component as BlogView,
and each post is rendered as a subcomponent BlogPostView.  Right now, I'm
passing the BlogView object into each BlogPostView object so that if a
BlogPostView's remove anchor is clicked, it verifies what they want to do, then
removes it from the collection I'm using to store the posts, and tells the
parent to re-generate it's list of children.

What I want is a way to remove the need for the BlogPostView to have to know
that a parent object even exists.  I want the BlogView to be able to generate a
new set of children each time it is displayed, but if I do that right now, then
any callbacks the children do are screwed up.  How do I get this parent view to
generate a new list each time it is displayed, but not keep the callbacks in the
children from working?

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

Re: Re: Finding the parent component of a rendered component

cdavidshaffer
Luke wrote:

> Ok, maybe someone can help me figure out the logic I want here better than what
> I have figured out.
>
> I'm making a blog system.  I have the main application component as BlogView,
> and each post is rendered as a subcomponent BlogPostView.  Right now, I'm
> passing the BlogView object into each BlogPostView object so that if a
> BlogPostView's remove anchor is clicked, it verifies what they want to do, then
> removes it from the collection I'm using to store the posts, and tells the
> parent to re-generate it's list of children.
>
> What I want is a way to remove the need for the BlogPostView to have to know
> that a parent object even exists.  I want the BlogView to be able to generate a
> new set of children each time it is displayed, but if I do that right now, then
> any callbacks the children do are screwed up.  How do I get this parent view to
> generate a new list each time it is displayed, but not keep the callbacks in the
> children from working?
>
>  
I'm not sure if this will work for you but one method I used in simple
cases is an "onAnswer:" block in the children...toy example:

Parent>>initialize
    super initialize.
    (child := Child new) onAnswer: [:answer | self updateList]



Child>>callbackWhenRemovePressed: theItem
    self removeTheItem: theItem.
    self answer: nil


This way you update your child list during a callback rather than on
rendering so you should have fewer "callback not found" problems.

David


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

RE: Re: Finding the parent component of a rendered component

Ramon Leon-5
In reply to this post by Luke Ivers

> Subject: [Seaside] Re: Finding the parent component of a
> rendered component
>
> Ok, maybe someone can help me figure out the logic I want
> here better than what I have figured out.
>
> I'm making a blog system.  I have the main application
> component as BlogView, and each post is rendered as a
> subcomponent BlogPostView.  Right now, I'm passing the
> BlogView object into each BlogPostView object so that if a
> BlogPostView's remove anchor is clicked, it verifies what
> they want to do, then removes it from the collection I'm
> using to store the posts, and tells the parent to re-generate
> it's list of children.
>
> What I want is a way to remove the need for the BlogPostView
> to have to know that a parent object even exists.  I want the
> BlogView to be able to generate a new set of children each
> time it is displayed, but if I do that right now, then any
> callbacks the children do are screwed up.  How do I get this
> parent view to generate a new list each time it is displayed,
> but not keep the callbacks in the children from working?
That's an interesting question and one that comes up often when writing
components.  There is a general solution to that whole class of problems.  

How do components communicate with other components while maintaining loose
coupling and remaining generally composable?  This problems was solved quite
elegantly by Vassili Bykov and his Announcements framework.

The basic idea is to setup an announcer somewhere global, in the session for
example.  

MySession>>announcer
    ^ announcer ifNil: [announcer := Announcer new]

Then sublcass Announcement for any interesting thing that might happen like
removing a child.  

Announcement subclass: #RemoveChild instanceVariableNames: 'child'

Any component interested in this announcement registers its interest when it
initializes.

Parent>>initialize
    super initialize.
    self session on: SARemoveChild send: #removeChild: to: self

Parent>>removeChild: anEvent
    self children remove: anEvent child

And any component who wants to fire this event simply announces it by
sending in an instance of that custom announcement object.

Child>>removeMe
    self session announce: (SARemoveChild child: self)

Works great, and depending on where you place the announcer, you could even
have different sessions sending events to each other, or different
applications.

Attached is a commented and working demo that uses announcements to solve
your remove child problem.

Ramon Leon
http://onsmalltalk.com


_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

SeasideAnnouncementDemo.st (4K) Download Attachment