From http://demo.qooxdoo.org/0.8.x/apiviewer/#qx.io.remote.Rpc~callAsync
callAsync(Function handler, String methodName)
Makes an asynchronous server call. The method arguments (if any) follow
after the method name (as normal JavaScript arguments, separated by commas,
not as an array).
When an answer from the server arrives, the handler function is called with
the result of the call as the first, an exception as the second parameter,
and the id (aka sequence number) of the invoking request as the third
parameter. If the call was successful, the second parameter is null. If
there was a problem, the second parameter contains an exception, and the
first one is null.
Parameters:
handler
the callback function.
methodName
the name of the method to call.
So I think your code could be something like that:
var getMenuHandler = function (data, exc,id) {
if (exc == null) {
// whatever you want to do
}
else { // the async call failed
alert(exc);
}
};
rpc.callAsync( getMenuHandler, "getMenuXml", null );
You could pass an parameter to the remote method instead of null.
Cheers,
Fritz
On Wed, 6 May 2009, Matthew Gregory wrote:
I haven't got the api in front of me but I think there is a different
function to use callback handlers. Instead of callAsync something like
"callWithHandlers"
sNIk wrote:
oh .. got it now. ive never done async-stuff, so i must rethink as u said. ;)
actually im not a webapp-programmer, its not hard but different than
programming a game or demo. no back to topic ;)
my approach:
var rpc = new qxgui.utils.Rpc;
rpc.callAsync( "getMenuXml", null );
rpc.addListener( "completed", function(e)
{
qxgui.reg.MenuXML.getInstance().setMenu( e.getData() );
});
for some reason the listener doesnt react.
any suggestions?
ps: i appreciate the great support in this mailing list!
regards
Andreas
Derrell Lipman wrote:
On Wed, May 6, 2009 at 9:24 AM, sNIk <[email protected]> wrote:
hello. at first the code ...
qx.Class.define("qxgui.reg.MenuXML",
{
extend: qx.core.Object,
type: "singleton",
construct: function()
{
var rpc = new qxgui.utils.Rpc;
rpc.callAsync( "getMenuXml", null, function( result )
{
qxgui.reg.MenuXML.getInstance().setMenu( result );
});
},
members:
{
// eigenschaften
////////////////////////////////////////////////////////////////////////
__menuxml: null,
// methoden
////////////////////////////////////////////////////////////////////////
setMenu: function( menuxml )
{
this.__menuxml = menuxml;
},
getMenu: function()
{
return this.__menuxml;
}
}
});
usage: var menu = qxgui.reg.MenuXML.getInstance().getMenu();
now back to my problem ... when i run alert( menuxml ) in setMenu, i get
the
right output (some xml stuff). actually, the result is saved in the
property
__menuxml, right?
but alert( menu ) gives me the damn null. any suggestions?
You're missing the main concept that it takes time (for the purpose of
this
discussion, assume 3 seconds even though that's unreasonably high in most
real scenarios) to issue your remote procedure call, have the backend
server
process the request and send back the response, and for the client
(qooxdoo
program) to receive the response and call your listener function which
calls
setMenu(). Therefore when you call qxgui.reg.MenuXML.getInstance() it
*begins* that process and returns. Three seconds later, the response
arrives, your listener is called, and therefore the menu property gets
set.
So what's happening when you just issue this:
var menu = qxgui.reg.MenuXML.getInstance().getMenu();
the request has been issued before getMenu() is called but the response
has
not yet arrived, so the value of the menu property is still null, thus
alert(menu) displays null. You are operating in an asynchronous world now,
not a synchronous one. You must organize your program around events, not
in-line code that you expect to block until a result arrives.
Hope that helps.
Derrell
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
--
Oetiker+Partner AG tel: +41 62 775 9903 (direct)
Fritz Zaucker +41 62 775 9900 (switch board)
Aarweg 15 +41 79 675 0630 (mobile)
CH-4600 Olten fax: +41 62 775 9905
Schweiz web: www.oetiker.ch
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel