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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Stephen Davies-3
Hi,

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?

Thanks,
Steve

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



_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Ajax using WebElements: how does Aida find and rerun the code?

Stephen Davies-3


2008/9/16 Stephen Davies <[hidden email]>
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.

Hmm - answering my own question,  Some messing in the debugger and I found #setCreationMethod in WebElement.

Which is kind of tricky-dicky..., but at least my mystery is solved: its done by magic...

Regards,
Steve


_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Ajax using WebElements: how does Aida find and rerun the code?

Janko Mivšek
In reply to this post by Stephen Davies-3
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


--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida
Reply | Threaded
Open this post in threaded view
|

Re: Ajax using WebElements: how does Aida find and rerun the code?

Janko Mivšek
In reply to this post by Stephen Davies-3
Stephen Davies wrote:

>     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.
>
>
> Hmm - answering my own question,  Some messing in the debugger and I
> found #setCreationMethod in WebElement.
>
> Which is kind of tricky-dicky..., but at least my mystery is solved: its
> done by magic...

Well, sometimes reflection capabilities of Smalltalk really help, as in
this case. Here another trick is also used, I'm calling it "climbing on
the stack". See how the reference to the WebApplication of the creation
method is found...

Janko

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si
_______________________________________________
Aida mailing list
[hidden email]
http://lists.aidaweb.si/mailman/listinfo/aida