On second thought, for your convenience, here is the code sample
private native void jsCallRemoteMethod(
String remoteClassName,
String remoteMethodName,
JavaScriptObject callParameters,
int remoteMethodCallDescriptorKey,
int callTimeout) /*-{
var me = this;
var remoteClass = $wnd[remoteClassName];
var remoteMethod = remoteClass[remoteMethodName];
var callMetadata = {
callback:
function(returnValue) {
var returnValueShell = {};
var
isReturnValueOfPrimitiveType = false;
var isReturnValueOfArrayType =
false;
if
(typeof(returnValue)=='object') {
returnValueShell =
returnValue;
}
if
(typeof(returnValue)=='number' ||
typeof(returnValue)=='string' || typeof(returnValue)=='boolean') {
returnValueShell =
{value: returnValue};
isReturnValueOfPrimitiveType = true;
}
if
(returnValue.constructor.toString().indexOf("Array") != -1) {
isReturnValueOfArrayType = true;
returnValueShell =
returnValue;
}
m...@com.eliasbalasis.dwr4gwt.client.DwrAdapter::fireRemoteMethodCallReply(Ljava/
lang/Boolean;Ljava/lang/Boolean;Lcom/google/gwt/core/client/
JavaScriptObject;I)
(
isReturnValueOfPrimitiveType,
isReturnValueOfArrayType,
returnValueShell,
remoteMethodCallDescriptorKey
);
},
timeout:
callTimeout,
errorHandler:
function(errorMessage) {
m...@com.eliasbalasis.dwr4gwt.client.DwrAdapter::fireRemoteMethodCallError(Ljava/
lang/String;I)
(
errorMessage,
remoteMethodCallDescriptorKey
);
}
};
var call = 'remoteMethod(';
var index = 0;
for (var key in callParameters) {
if (index>0)
call += ',';
call += 'callParameters.'+String(key);
index += 1;
}
if (index>0)
call += ',';
call += 'callMetadata)';
eval(call);
}-*/;
remoteClassName, remoteMethodName, callParameters define which
javascript method must be called resulting in call variable in the end
having a value like
'remoteMethod[callParameters.param1,]callParameters.param2,callParameters.paramN,callMetadata)'
but remoteClassName, remoteMethodName, callParameters are mangled so
here is a better version that used either the mangled names or the
original ones depending on what is available (implying being in hosted
mode or not). but it works only if the mangled names do not change.
Currently they don't unless the JSNI code is changed which is
acceptable.
private native void jsCallRemoteMethod(
String remoteClassName,
String remoteMethodName,
JavaScriptObject callParameters,
int remoteMethodCallDescriptorKey,
int callTimeout) /*-{
var me = this;
var remoteClass = eval('$wnd.'+remoteClassName);
var remoteMethod = remoteClass[remoteMethodName];
var callMetadata = {
callback:
function(returnValue) {
var returnValueShell = {};
var isReturnValueOfPrimitiveType = false;
var isReturnValueOfArrayType = false;
if (typeof(returnValue)=='object') {
//$wnd.alert("returnValue is an object");
returnValueShell = returnValue;
}
if (typeof(returnValue)=='number' ||
typeof(returnValue)=='string' || typeof(returnValue)=='boolean') {
//$wnd.alert("returnValue is of primitive type
(number,string,boolean)");
returnValueShell = {value: returnValue};
isReturnValueOfPrimitiveType = true;
}
if (returnValue.constructor.toString().indexOf("Array") != -1) {
//$wnd.alert("returnValue is an array");
isReturnValueOfArrayType = true;
returnValueShell = returnValue;
}
//$wnd.alert("isReturnValueOfPrimitiveType =
"+isReturnValueOfPrimitiveType);
//$wnd.alert("isReturnValueOfArrayType =
"+isReturnValueOfArrayType);
me.@com.eliasbalasis.dwr4gwt.client.DwrAdapter::fireRemoteMethodCallReply(Lcom/
google/gwt/core/client/JavaScriptObject;IZZ)
(
returnValueShell,
remoteMethodCallDescriptorKey,
isReturnValueOfPrimitiveType,
isReturnValueOfArrayType
);
},
timeout:
callTimeout,
errorHandler:
function(errorMessage) {
me.@com.eliasbalasis.dwr4gwt.client.DwrAdapter::fireRemoteMethodCallError(Ljava/
lang/String;I)
(
errorMessage,
remoteMethodCallDescriptorKey
);
}
};
// use hosted mode variable names
// assuming we are in hosted mode
var remoteMethodExpression = 'remoteMethod';
var callParametersExpression = 'callParameters';
var callMetadataExpression = 'callMetadata';
var isWebMode = false;
try {
eval('remoteMethod');
} catch(ex) {
var isWebMode = true;
}
if (isWebMode) {
// we are not in hosted mode
// use mangled/translated variable names
// we are in web mode
remoteMethodExpression = 'q';
callParametersExpression = 'h';
callMetadataExpression = 'f';
}
var call = remoteMethodExpression+'(';
var index = 0;
for (var key in callParameters) {
if (index>0)
call += ',';
call += callParametersExpression+'.'+String(key); //
index += 1;
}
if (index>0)
call += ',';
call += callMetadataExpression+')'; //
eval(call);
}-*/;
On Jan 6, 4:56 pm, "
eliasbala...@gmail.com" <
eliasbala...@gmail.com>
wrote:
> I am using 'eval' in JSNI function to make a call to a javascript
> method that is programmatically discovered (name and parameters are
> passed as arguments to JSNI function)
> Here is a related post containing more details and a real code
> snapshot.
>
>
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/threa...