[aida] Ajax using WebElements: how does Aida find and rerun the code?

Janko Mivšek janko.mivsek at eranova.si
Tue Sep 16 21:51:51 CEST 2008

Hello Steve,

Welcome to the Aida community! See the answer bellow.

Stephen Davies wrote:

> I did this:
> viewMain
> | e time |
> e := WebElement new.
>         "..."
> time := self timeField.
> time updateEverySeconds: 1.
> e add: time; addBreak.
>         "..."
> timeField
> | e |
> e := WebElement new.
> e style: ''.
> e addTextBold: Date today printString, ' ', Time now printString.
> ^ e
> So this works perfectly - my time dutifully updates.
> But for the life of me I cannot figure out how Aida knows to call the 
> timeField method in order to get the new time.
> I see that the generated web page marks the field with a div id:
> <div style="" id="id94">
>     <b>16 September 2008 9:02:57 pm</b>
> </div>
> <script type="text/javascript">; new Ajax.PeriodicalUpdater('id94', '/addressbook.html', {method: 'post', postBody: 'view=main&ajaxRequest&ajaxGetElementId=id94', evalScripts: true, frequency: 1});</script>
> So Aida gets the post saying element id id94 must be updated.  But how 
> does Aida get from that to a call to my #timeField method?
> Can someone enlighten me?

A bit of magic never hurts ;)

But seriously, trick is in registering the creation method in 
WebElement, then you simply call that method and you get an element 
refreshed. Creation method is set when an element is created (see 
WebElement class new).

To understand how Ajax then refreshes the right element, see 
WebApplication respondToAjaxRequest: and ajaxUpdateOfOld:, where you can 
see how the right method is found from the element to be refreshed.

> PS: Hope you don't mind a bunch of questions like this from a newbie.

Not at all, we are just collecting questions for FAQ anyway ;)

Best regards

Janko Mivšek
Smalltalk Web Application Server

More information about the Aida mailing list