Search code examples
smalltalkpharoseaside

Timer callback in Pharo smalltalk + Seaside


I've just ported my Dolphin Smalltalk + Seaside application to the latest Pharo Smalltalk 4.0 and Seaside 3.1. In it, I need a callback every second from the (browser) client to the (Pharo) server to update the view.

I had this piece of code to press the "Update" button automatically every second. But it does not work anymore after the port to Pharo:

html script: (
    ( html jQuery: '#updateButton' ) 
        call: 'click';
        interval: 1000 ).

I've searched the net for other (more elegant?) solutions but can't seem to get them to work. Can anybody give me a hint on how to proceed?

This is the JavaScript code that is generated by the code above and which used to work in Dolphin + Seaside:

<script type="text/javascript">
/*
<![CDATA[/setInterval(function(){$("#updateButton").cl‌​ick()},2000)/]]>
*/</script> 

Solution

  • I suppose that the server callback is attached to the button with id #updateButton? It is odd that you have a script that triggers a click action on that button instead of triggering a callback every xx seconds.

    The following script would update the entire body every 10 seconds. Given that you implement the right rendering methods, this is probably a more elegant solution:

    html script: (
        ((html jQuery: 'body') load
            html: [ :innerHtml | self renderOn: innerHtml ]) 
                interval: 10000)