To set up client-server RPC we need to create one interface defining the RPC methods, and then make use of that interface on both the client and the server. Place the interface in the client package:
Java
Note that the RPC methods can not have return values. In this example, we pass MouseEventDetails
to get a more complete example, but you could pass almost any (or no) parameters.
Java
Here we react to the RPC call by incrementing a counter. We do not make use of the (yet). Notice the important call to registerRpc()
in the added constructor.
In the client side MyComponentConnector
, we use to get an implementation of the RPC interface, and call the clicked()
method when the widget is clicked:
Notice that most of the code is for attaching the click handler and creating the MouseEventDetails
, the code for the actual RPC is quite minimal.
Compile the widgetset, and the label text should be updated with the click count whenever you click it (remember that the counting is done on the server-side).
Finally, note that you can use multiple RPC interfaces in one component, allowing for better code separation and reuse.