Reputation: 107
I wanted to see if there is any possibility in Seaside that a child component gets the reference to the parent component, without using the session or parameter passage. That is, the child component making, for example, a call to self gets the parent component.
Upvotes: 2
Views: 131
Reputation: 15907
The normal way of dealing with this in Seaside is to connect the component loosely to its parent using announcements. The parent wires up its children to send it back an announcement.
See: this example
Upvotes: 0
Reputation: 457
Iirc, the absence of a reference to a Component's parent was a conscious design decision. It is important for keeping components decoupled and self-contained. This is not to say that esteban's suggestion is wrong, we've also implemented something similar. You can do it, but it may have consequences like lingering references and hurdles to the reusability of components.
Upvotes: 2
Reputation: 1218
The short answer is that there is no simple way to do that.
The reason is that subclasses of WAComponent
(and also WAPresenter
) have no direct reference to a parent component, since for rendering purposes this is not needed, because the visitor performs a top-down path and depending on a parent element introduces a coupling of some sort, and an instance variable that might not be used.
To overcome that, I have my own WAComponent
subclass, let's call it EAMComponent
and this component has a parent
instance variable (and in my case, also a model
instance variable).
The EAMComponent class
implements on: modelObject in: parentComponent
(as well as on:
and in:
that depend on the former, influenced by Dolphin's implementation of Model-View-Presenter).
So then on the parent component the resulting idiom is something like:
createChildrenComponents
dateComponent := EAMTextComponent on: self date in: self.
footerComponent := EAMFooterComponent in: self.
Then in the footer component you can easily refer to the parent
that is the object passed as argument to the in:
part of the selector.
Upvotes: 6