[Seaside] Setting instance variables

Avi Bryant avi@beta4.com
Thu, 6 Jun 2002 00:20:14 -0700 (PDT)


On Wed, 5 Jun 2002, Jim Benson wrote:

> [Each calendar has a previous/next button, so that the user can flip through
> the calendar]. I haven't been able to figure out when or how to do that in
> Seaside, which probably indicates that I don't quite understand how the
> instance creation sequence takes place, or where to jump in when I want to
> fiddle around with something that the template creates.

Right.  The way you jump in to fiddle with the template is in the
#addBindingsTo: method.  There's actually no easy way to get hold of the
instance as it's created to initialize it, which in retrospect there
probably should be (suggestions for how this wants to work are welcomed).
However, you can use bindings to do what you need, if somewhat awkwardly.
In particular, I would:

- add instance variables for, say, currentMonth and previousMonth to the
parent
- initialize these to the correct month values in the parent's #initialize
- do one of two things:
  - explicitly add bindings in the parent's addBindingsTo: method such as
     (template elementNamed: 'previousMonth')
        bind: #month toPath: 'previousMonth'
  - or, write a defaultBindings method for your month component that sets
up a binding based on its id:
    MonthComponent>>defaultBindings
      self bind: #month toPath: id
Now whenever you use a month component, it'll default to syncing itself
with a month instance variable in the parent with the same name as its id.

Note that this doesn't just provide for initialization - the inst vars in
the parent will always reflect the current month in the components (and
changing them will also change the components).

That make any sense at all?

Avi