er.ajax
Class AjaxProxy
java.lang.Object
com.webobjects.appserver.WOElement
com.webobjects.appserver.WOComponent
er.ajax.AjaxComponent
er.ajax.AjaxProxy
- All Implemented Interfaces:
- WOActionResults, NSKeyValueCoding, NSKeyValueCoding.ErrorHandling, NSKeyValueCodingAdditions, NSValidation, IAjaxElement, Serializable, Cloneable
public class AjaxProxy
- extends AjaxComponent
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
- Complete the JSON-RPC integration to be able to leverage all possibilities of that library (foreign references,
etc.).
- Version:
- $Revision $, $Date $
© 2005-2006 OS communications informatiques, inc. http://www.os.ca
Tous droits r�serv�s.
- Author:
- Jean-Fran�ois Veillette
- See Also:
- Serialized Form
| Bindings |
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. |
| Methods inherited from class er.ajax.AjaxComponent |
_containerID, addScriptResourceInHead, addScriptResourceInHead, addStylesheetResourceInHead, addStylesheetResourceInHead, appendTagAttributeToResponse, appendToResponse, booleanValueForBinding, invokeAction, safeElementID, valueForBinding, valueForBinding, valueForBinding |
| Methods inherited from class com.webobjects.appserver.WOComponent |
__valueForBinding, _associationWithName, _awakeInContext, _childTemplate, _cleanUpStatelessComponent, _componentDefinition, _componentUnroll, _isPage, _setContext, _setIsPage, _setParent, _setSubcomponent, _sleepInContext, _subcomponentForElementWithID, _templateNameForClass, _unroll, application, awake, baseURL, bindingKeys, canAccessFieldsDirectly, canGetValueForBinding, canSetValueForBinding, clone, context, debugString, descriptionForResponse, ensureAwakeInContext, frameworkName, generateResponse, handleQueryWithUnboundKey, handleTakeValueForUnboundKey, hasBinding, hasSession, isCachingEnabled, isEventLoggingEnabled, logString, name, pageWithName, parent, path, pathURL, performParentAction, pullValuesFromParent, pushValuesToParent, reset, session, set_componentUnroll, set_unroll, setCachingEnabled, setValueForBinding, sleep, takeValueForKey, takeValueForKeyPath, takeValuesFromRequest, template, templateWithHTMLString, templateWithHTMLString, templateWithName, toString, unableToSetNullForKey, validateTakeValueForKeyPath, validateValueForKey, validationFailedWithException, valueForBinding, valueForBooleanBinding, valueForIntegerBinding, valueForKey, valueForKeyPath, valueForNSArrayBindings, valueForNSDictionaryBindings, valueForNumberBinding, valueForStringBinding |
AjaxProxy
public AjaxProxy(WOContext context)
isStateless
public boolean isStateless()
- Overridden because the component is stateless
- Overrides:
isStateless in class WOComponent
synchronizesVariablesWithBindings
public boolean synchronizesVariablesWithBindings()
- Overridden because the component does not synch with the bindings.
- Overrides:
synchronizesVariablesWithBindings in class WOComponent
addRequiredWebResources
protected void addRequiredWebResources(WOResponse res)
- 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_".
- Specified by:
addRequiredWebResources in class AjaxComponent
- Parameters:
res -
handleRequest
public WOActionResults handleRequest(WORequest request,
WOContext context)
- Ask the an JSONRPCBridge object to handle the json request.
- Specified by:
handleRequest in interface IAjaxElement- Specified by:
handleRequest in class AjaxComponent
Copyright © 2002 – 2007 Project Wonder.