[Seaside] SeasideAsync and Scriptaculous

Michel Bany m.bany at wanadoo.fr
Wed Nov 22 09:28:24 UTC 2006


There are many differences between SeasideAsync and Scriptaculous.
Speaking with the Scriptaculous semantics, SeasideAsync only supports
ajax things (i.e. updaters, requests, evaluators and periodicals) while
Scriptaculous can do a lot more things like effects, triggers, drag/ 
drop.

Also there are many differences in how the ajax things are done by
SeasideAsync and Scriptaculous. For the ajax things, SeasideAsync
has two concepts : live requests and event trackers, Scriptaculous
has four (i.e. updaters, requests, evaluators and periodicals).

A Scriptaculous updater results in a callback block being evaluated
on the server like this

		onClick: ( html updater
					id: 'counter';
					callback: [ :h | h render: count ] )

This callback generates an HTTP response containing some text
data. It can be just plain data or it can be an fragment of XHTML.
This text data replaces the contents of some html element
in the page which has been explicitely designated by the
Scriptaculous updater using the #id: message

		html span
				id: 'counter';
				with: count.

This means that a Scriptaculous updater can only update one
html element at a time. If you need to update multiple html elements
in a page, then you need to stack multiple updaters like this

		onClick: ( html updater ...);
		onClick: ( html updater ...);

On the opposite, SeasideAsync can update multiple html elements
in one callback, like this.

		onClickCallback: [ :e :h |
			h span id: 'counter1'; with: count1.
			h span id: 'counter2'; with: count2].

This callback generates an HTTP response containing a well-formed
XML document. This XML document is parsed and the contents of each
xml element found with an id= attribute is used for replacing the  
matching
html element in the page (matching means same id= attribute value).
If the XML document produced by the live callback happens to contain
some script elements, these scripts are always evaluated (unlike  
Scriptaculous
that requires sending #evalScripts: true to the updater). If nothing  
useful can be
done with the XML document, i.e. no replacement and no script  
evaluation,
this is considered as an application bug and a javascript alert  
occurs showing
the contents of the XML document.

Another difference between the Scriptaculous updater callback and the
SeasideAsync callback. The Scriptaculous callback takes only one  
argument,
the canvas where to write the response. The SeasideAsync takes two  
arguments,
an event object and the canvas where to write the response. The event  
object is
an instance of WALiveEvent and describes the actual event that  
triggered the
live callback. It holds information about when the ajax occured in  
the client,
what type of event, what html element triggered the event, what type  
of element,
the value of the html element...

The above applies only to SeasideAsync event tracking callbacks  
(#onEvent:callback:)
For live requests (#liveCallback:), the callback block takes also two  
argument,
but the first argument is the value of the html element (extracted  
from the event object
as a matter of fact).

HTH
Michel.






More information about the Seaside mailing list