[Seaside] Repainting during AJAX callbacks
C. David Shaffer
cdshaffer at acm.org
Thu May 26 14:55:47 UTC 2011
On 05/26/11 09:30, Runar Jordahl wrote:
> Thanks Boris! This works great. I can see the need for a
> mini-framework for this, but that is easy to build once you get your
> example to work.
> Boris' example assumes you have an element named 'orca-ss-balance' on
> the page. So BalanceDisplay would typically render like this:
> html div id: 'orca-ss-balance'; with: [ ... ]
> One thing to watch out for when using Boris' example, is creation of
> two nested elements with the same ID ('orca-ss-balance') after the
> first repaint is done: The first rendering should include the element
> with the ID, the second rendering (the repaint) should not include it.
> "Repaintable" has logic to take care of this.
While Repaintable is completely flexible in terms of what gets repainted
and how it is nested it does provide the convenience method #repaint to
handle the common "component in a DIV with a fixed id" pattern. I use
this a lot and find it quite liberating. Repaintable also handles the
case when a repaint is requested outside of an ajax callback (for
example, during a normal callback) by simply not repainting the
component (since it will be rendered during the render phase). This
often happens when a non-ajax callback causes an announcement which
triggers a repaint.
On the negative side Repaintable does not use #render: so ignores any
delegation (or decoration) that the component has. In practice this
works fine since the DIV that contains the component isn't on the page
if the component has delegated (via #call:, for example) to another
component so re-rendering the component has no effect (except possibly
on performance). This wasn't a design decision, though, just one of
convenience. I might work towards full rendering later. I'm using
Repaintable in a second application under development now so I hope some
of the rough edges will disappear as that project progresses.
More information about the seaside