My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.synthful.gwt.javascript.client;

import org.synthful.gwt.javascript.client.DomUtils;

import com.google.gwt.core.client.JavaScriptObject;
/**
*
* @author Icecream
* JSON Remote Script Call inserts a <script src='datasrc'> tag
* in the client document.<br>
*
* It defines a callback function on the client document.<br>
*
* The server datasrc has to be in proper javascript format, with the data
* enclosed within the callback function, so that on loading into the client
* document, the callback function would execute with the enclosed json data
* as its argument.
*
* Example javascript data:
* <pre>
* hello( {json data});
* </pre>
*
* alternatively:
* <pre>
* var x = {json data};
* hello(x);
* </pre>
*
* Which means a call need be about json but executing a complete javascript.
*
*/
abstract public class JsonRemoteScriptCall
{
public JsonRemoteScriptCall() {}

/**
* use this call if dynamic remote data source and therefore able to
* dynamically code the callback js function at the end of the json stream.
*
* This procedure would generate a unique js function name and
* send the server with reqestURI?callBackParameter=uniquelyGeneratedJsFunctionName
* so that the server-side would expect
* <ul>
* <li> to grab uniquelyGeneratedJsFunctionName thro callBackParameter,
* <li> and then generate the json,
* <li> assign a var to that json, var whatever={json structure}
* <li> append to the end of the json the JS functon call:<br/>
*
* uniquelyGeneratedJsFunctionName(whatever);
*
*/
public void callByCallBackParameter( String url, String callBackParameter )
{
String uniqCallbackName = "jsonRSC"+this.hashCode();
url = url +'?'+ callBackParameter +'='+ uniqCallbackName;
call( url, uniqCallbackName );
}

/**
* use this call if remote data source is static file and the callback
* has be hard-coded at the end of the json file,
* where you predetermine the name of the callbackJsFunctionName,</br>
*
* and made sure you appended that you assigned the json structure to a var
* and then appended the function call</br>
* callbackJsFunctionName(whatever);</br>
* to the end of the json structure.</br>
* Then bridgeCallbackNames would map that callbackJsFunctionName to
* the GWT method name onJsonRSCResponse.</br>
* DomUtils.jsAddScript would read the jsonp and insert it as a script into the local DOM,
* resulting in the json being converted into a JavascriptObject.
* Then eval would call callbackJsFunctionName with the JavascriptObject as argument,
* which in effect is calling onJsonRSCResponse with the JavascriptObject as argument.
*/
public void call( String url, String callbackJsFunctionName )
{
bridgeCallbackNames( this, callbackJsFunctionName );
DomUtils.jsAddScript(url);
}

private native static void bridgeCallbackNames(
JsonRemoteScriptCall hdlr, String callbackName )/*-{
jsonRSCcallback = function( j ){
hdlr.@org.synthful.gwt.javascript.client.JsonRemoteScriptCall::onJsonRSCResponse(Lcom/google/gwt/core/client/JavaScriptObject;)( j );
};
eval( "window."+callbackName+"=jsonRSCcallback" );
}-*/;

/*
$wnd[callbackName] = function(j) {
hdlr.@org.synthful.gwt.javascript.client.JsonRemoteScriptCall::onJsonRSCResponse(Lcom/google/gwt/core/client/JavaScriptObject;)( j );
}
*/

abstract public void onJsonRSCResponse( JavaScriptObject jso );
}

Change log

r98 by BlessedGeek on Jul 21, 2010   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r93 by BlessedGeek on Jul 19, 2010   Diff
[No log message]
r84 by BlessedGeek on Jun 30, 2010   Diff
[No log message]
All revisions of this file

File info

Size: 3746 bytes, 97 lines
Powered by Google Project Hosting