Get parent component in Seaside

131 Views Asked by At

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.

3

There are 3 best solutions below

0
Esteban A. Maringolo On BEST ANSWER

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.

1
Joachim Tuchel On

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.

0
Stephan Eggermont On

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