AjaxProxy Class Reference

Inherits er::ajax::AjaxComponent.

Collaboration diagram for AjaxProxy:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 AjaxProxy (WOContext context)
WOActionResults handleRequest (WORequest request, WOContext context)
boolean isStateless ()
boolean synchronizesVariablesWithBindings ()

Protected Member Functions

void addRequiredWebResources (WOResponse res)

Static Private Attributes

static final Logger log = Logger.getLogger(AjaxProxy.class)


Detailed Description

Handles javascript-java communication (client-server) between the javascript world running in a web browser and the java world, running in a WebObject application. This remote-procedure-call communication is done using json protocol, as implemented by the JSON-RPC library.

This component generate javascript code that will initialize a variable that will be the starting point for rpc communication. The name of this variable is given in the name binding. There will be an object, server side that will be the proxy and will handle the request. You can define the proxy on the server side (it has to be a JSONRPCBridge). The proxy will be your window to the java world, from there you can access your java objects from the javascript side. The name for this java variable is proxyName. By default, it will configure the parent component as one java proxy object and name it wopage from the javascript side. A JSONRPCBridge object is created if not given as a binding. If the binding is there but the value is null, it will create the bridge then push it to the binding. That way, you can configure a single bridge for multiple proxy objects. It is of good practice to provide a value in a binding (at least a binding) so that the object is not created on every ajax request.

The proxy object will be the one visible for RPC from the javascript world. For example, the following binding:
PageProxy : AjaxProxy {
proxyName = "wopage";
name = "jsonrpc";
}

will be used as follow :
JavaScript (client) Java (server)
// index of the selection on the client;
var idx = 3; // fixed value for the demo
// using rpc, ask our page to get the name for that client for that index.
var nom = jsonrpc.wopage.clientNameAtIndex(idx);
// Java-WebObject side, we receive the index and simple return what they asked for, as for any java call. public String clientNameAtIndex(int i) {
return "something!"+i;
}

Remember that is no proxy object is given, it will use the parent component, which is the component in which this component is embeded.

Todo

proxy Server side object (Java) that will be visible for rpc communication (Javascript). If no object is bound, the parent() object is assigned by default. proxyName Client side name (Javascript) used to identify the proxy (Java) from the bridge object. name Client side name (Javascript) of the bridge object. JSONRPCBridge Server side object (Java) used to handle the request. Of no value are bound, a new object is created for every ajax request. If a binding is there but null value, a new object will be created and pushed to the binding so that this new object can be shared for multiple proxy.

Author:
Jean-François Veillette <jfveillette@os.ca>
Version:
$Revision $, $Date $
© 2005-2006 OS communications informatiques, inc. http://www.os.ca Tous droits réservés.

Constructor & Destructor Documentation

AjaxProxy ( WOContext  context  ) 


Member Function Documentation

void addRequiredWebResources ( WOResponse  res  )  [protected, virtual]

Adds the jsonrpc.js script to the head in the response if not already present and also adds a javascript proxy for the supplied bridge under the name "JSONRPC_<variableName>".

Parameters:
res 

Implements AjaxComponent.

WOActionResults handleRequest ( WORequest  request,
WOContext  context 
) [virtual]

Ask the an JSONRPCBridge object to handle the json request.

Implements AjaxComponent.

boolean isStateless (  ) 

Overridden because the component is stateless

boolean synchronizesVariablesWithBindings (  ) 

Overridden because the component does not synch with the bindings.


Member Data Documentation

final Logger log = Logger.getLogger(AjaxProxy.class) [static, private]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:42:38 2012 for Project Wonder by  doxygen 1.5.8