[Seaside] Sending messages to javascript objects
Andres Fortier
andres at lifia.info.unlp.edu.ar
Fri Apr 25 15:24:29 UTC 2008
Hi list,
from the examples I've seen so far, the
basic mechanism to update (a part of) a page is to
split the page rendering in many #renderXYZOn: and then
using an updater to refresh a specific part of the page
by calling the appropriate #renderXYZOn:.
Now, even though possible, in some cases it is a waste
of user time and bandwidth to re-render a whole
component, when that can be done by just sending a
javascript message. To be concrete, suppose I have a
page with a google map component and a checkbox to
decide whether the map should show the google bar or
not. Using the first approach, the page would look like:
html checkbox
value: self map isGoogleBarEnabled;
onChange: (html updater
id: self map containerId;
callback: [:renderer |
self map toggleGoogleBar.
renderer render: self map]).
however, this means that toggling a checkbox would
reload the whole map, which is definitely perceived by
the user and expensive in terms of network bandwidth.
Now, in terms of javascript this can be achieved by
just sending the message enable/disableGoogleBar() to
the map object, which can be coded as:
html checkbox
id: 'choice_chk';
value: self map isGoogleBarEnabled;
onChange: ('if
(document.getElementById(''choice_chk'').checked)
{' , self map id , '.enableGoogleBar();}
else {' , self map id , '.disableGoogleBar();}').
However, this approach means that:
1. The map model living in the Smalltalk image (i.e.
"self map") is not synchronized with the map in the
page, since it didn't receive the toggle notification.
2. The script is "static" in terms that it can't take
decisions in terms of the current state of the St
image. It can just code the app state in the script at
the time the page was rendered, something that may not
be consistent over time.
3. Even though a definitely minor issue, I have to
write javascript.
To solve the first problem the first thing that comes
to my mind is replicating the effort, by also attaching
a callback that updates the model, which I'm not very
fond of. The second one seems a bit more weird, since
I would need to coordinate St objects with javascript
objects. So I was wondering if there already is a
standard mechanism to handle this kind of situations. I
started thinking about a seamless way of interacting
with javascript objects from Smalltalk by some sort of
proxies, but I don't want to put up a new machinery if
there this has already been solved.
Thanks in advance,
Andrés
More information about the seaside
mailing list