Prev | Current Page 104 | Next

Frank Zammetti

"Practical DWR 2 Projects"


In the DWR model, the calling ???system??? is JavaScript executing in the users??™ browser, and
the system being called is the Java classes running on the server. Just like other forms of RPC,
the code you write in JavaScript looks very similar to the code you??™d write on the server to execute
the same code. There are, of course, some differences as you??™d expect given the inherent
differences between JavaScript and Java, but by and large it??™s extremely similar.
CHAPTER 1 n AN INTRODUCTION TO AJAX, RPC, AND MODERN RIAS 39
To give you a brief preview, consider the following simple class definition:
package com.company.app;
public class MyClass {
String sayHello(String name) {
return "Hello, " + name;
}
}
If you wanted to call this code via DWR from JavaScript running in the browser, assuming
you??™d already accomplished all the necessary setup, the following code is all it would take:
MyClass.sayHello("Frank", sayHelloHandler);
var sayHelloHandler = function(data) {
alert(data);
}
As I mentioned, and as you can see, the call syntax is very much like you??™d do from Java,
with the addition of the second parameter, which as it turns out is a callback function that will
be executed when the method invocation completes.


Pages:
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116