AJAX-related: Howto use XMLRPC with activewidgets
Hi,
Since I could not find anything about XMLRPC, I thought you might be interested in this.
To be a "proper" Ajax application it comes in handy to use XMLRPC, and in fact there is really one major advantage over plain XMLHTTPRequests:
XMLRPC knows about simple types. Which includes integers, floats, boolean, lists = arrays, dictionaries = objects = associative arrays, binary and of course strings.
BTW: The server I use is Zope (http://www.zope.org)
Having a server that understands XMLRPC, you are able to call methods with typed parameters, thus making it possible to avoid writing your own marshalling and unmarshalling functions. (Un/Marshalling is the process of transforming simple types into XML and back. Actually marshalling is not limited to XMLRPC, it's for all protocols. JSON is an example for another suitable protocol.)
You can easily use XMLRPC with ActiveWidgets, too! [Ah! we're getting to the point finally.]
Here is an example using "jsolait" (a javascript "framework", which has a fairly stable xmlrpc client: http://www.jsolait.net).
But you might use "sarissa" as well - just a matter of taste, I suppose.
I apologize I cannot give you a complete working example right now, due to the lack of a server _not_ behind a firewall. Since I'm working on a project to integrate ActiveWidgets into Plone (a Zope CMS, http://plone.org), I'll come up with an example - hopefully before my summer holiday ;)
Sorry for the 'Ajax' buzzword in the topic -- I could not resist. :-)
Since I could not find anything about XMLRPC, I thought you might be interested in this.
To be a "proper" Ajax application it comes in handy to use XMLRPC, and in fact there is really one major advantage over plain XMLHTTPRequests:
XMLRPC knows about simple types. Which includes integers, floats, boolean, lists = arrays, dictionaries = objects = associative arrays, binary and of course strings.
BTW: The server I use is Zope (http://www.zope.org)
Having a server that understands XMLRPC, you are able to call methods with typed parameters, thus making it possible to avoid writing your own marshalling and unmarshalling functions. (Un/Marshalling is the process of transforming simple types into XML and back. Actually marshalling is not limited to XMLRPC, it's for all protocols. JSON is an example for another suitable protocol.)
You can easily use XMLRPC with ActiveWidgets, too! [Ah! we're getting to the point finally.]
Here is an example using "jsolait" (a javascript "framework", which has a fairly stable xmlrpc client: http://www.jsolait.net).
But you might use "sarissa" as well - just a matter of taste, I suppose.
<!-- don't forget to load the jsolait library -->
<script type="text/javascript" src="jsolait/init.js"></script>
<script type="text/javascript">
// importModule is a jsolait function injected into the global namespace
// 'xmlrpc' is the jsolait xmlrpc library, as you might have guessed
var xmlrpc = importModule('xmlrpc');
// don't forget the '/' at the end
// for security reasons the server must be the same server which
// served this very page
var server = "http:my.server.com:my_port/some_url/";
// the method name
// do NOT supply parameters with method?arg1=foo&arg2=bar
var method = "my_method/maybe/with/a/path";
var get_data = new xmlrpc.XMLRPCMethod(server,method);
// Now you can use "get_data" XMLRPCProxyMethod to get the data.
// The arity of the function is variable, use as many parameters
// as the serverfunction expects.
// If the last parameter is a function, it will be used as callback, making
// the call an async one.
// sync call example:
var result = get_data({id:'42',prop:['sample','values']},3.1428,false);
// where result may contain any simple type including javascript objects
// same as async call:
var result = get_data({id:'42',prop:['sample','values']},3.1428,false,callback);
// the callback must have two parameters
callback = function(result, error) {
if (error) {
alert(error); // the server returned an error, this is the msg
} else {
// do what you please with the result...
// maybe you must convert the data-model?
convert_model(result);
// or save the result in a global variable for reuse?
globalServerModel = result;
// or the server returned a fitting two dimensional array?
myGrid.setProperty('data/text',result);
}
}
</script>
I apologize I cannot give you a complete working example right now, due to the lack of a server _not_ behind a firewall. Since I'm working on a project to integrate ActiveWidgets into Plone (a Zope CMS, http://plone.org), I'll come up with an example - hopefully before my summer holiday ;)
Sorry for the 'Ajax' buzzword in the topic -- I could not resist. :-)
Sebastian Wiemer (NIONEX)
July 6,