|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.gwtext.client.core.JsObject com.gwtext.client.data.DataProxy com.gwtext.client.data.ScriptTagProxy
public class ScriptTagProxy
An implementation of DataProxy that reads a data object from a URL which may be in a domain other than the originating domain of the running page.
Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain of
the running page, you must use this class, rather than HttpProxy
.
The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript source code that is used as the source inside a <script> tag.
In order for the browser to process the returned data, the server must wrap the data object with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy. Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy depending on whether the callback name was passed:
boolean scriptTag = false;
String cb = request.getParameter("callback");
if (cb != null) {
scriptTag = true;
response.setContentType("text/javascript");
} else {
response.setContentType("application/x-json");
}
Writer out = response.getWriter();
if (scriptTag) {
out.write(cb + "(");
}
out.print(dataBlock.toJsonString());
if (scriptTag) {
out.write(");");
}
Consider the following code :
RecordDef recordDef = new RecordDef(new FieldDef[]{
new StringFieldDef("name", "name"), // "mapping" property not needed if it's the same as "name"
new StringFieldDef("occupation") // this field will use "occupation" as the mapping.
});
JsonReader reader = new JsonReader(new JsonReaderConfig() {
{
setTotalProperty("results"); // The property which contains the total dataset size (optional)
setRoot("rows"); // The property which contains an Array of row objects
setId("id"); // The property within each row object that provides an ID for the record (optional)
}}, recordDef);
If the data is being server from the same domain, then you don;t need to use ScriptTagProxy but instead need to use
HttpProxy
pointing to the URL that returns data in the following format :{ 'results': 2, 'rows': [
{ 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
{ 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
}
However if this data is being read from another domain, a couple of things need to be done.
ScriptTagProxy proxy = new ScriptTagProxy("http://externalurl:8023/foo/bar.php");
Now bar.php cannot return standard Json like the one above when using HttpProxy. Instead it needs to wrap the
Json data in a callback. This is required when reading data from antoher domain. When the ScriptTagProxy tries
for fetch data, it will issue an HTTP request to the specified URL passing the name of the callback function that
it needs the results to be wrapped in. For example http://externalurl:8023/foo/bar.php?start=0&limit=25&sort=nome&dir=DESC&_dc=1196661274168&callback=stcCallback1002
stcCallback1002({ 'results': 2, 'rows': [
{ 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
{ 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' }]);
}
ScriptTagProxy(String, int, String)
.
Field Summary |
---|
Fields inherited from class com.gwtext.client.core.JsObject |
---|
jsObj |
Constructor Summary | |
---|---|
ScriptTagProxy(java.lang.String url)
Construct a new ScriptTagProxy. |
|
ScriptTagProxy(java.lang.String url,
int timeout)
Construct a new ScriptTagProxy. |
|
ScriptTagProxy(java.lang.String url,
int timeout,
java.lang.String callbackParam)
Construct a new ScriptTagProxy. |
Method Summary | |
---|---|
protected com.google.gwt.core.client.JavaScriptObject |
create(com.google.gwt.core.client.JavaScriptObject config)
|
Methods inherited from class com.gwtext.client.core.JsObject |
---|
getJsObj, getProperties, isCreated, setJsObj |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ScriptTagProxy(java.lang.String url)
url
- the URL from which to request the data object.public ScriptTagProxy(java.lang.String url, int timeout)
url
- the URL from which to request the data object.timeout
- the number of milliseconds to wait for a response. Defaults to 30 seconds.public ScriptTagProxy(java.lang.String url, int timeout, java.lang.String callbackParam)
url
- the URL from which to request the data object.timeout
- the number of milliseconds to wait for a response. Defaults to 30 seconds.callbackParam
- the name of the parameter to pass to the server which tells the server the name of the callback function set up by the load call to process the returned data object. Defaults to "callback".
The server-side processing must read this parameter value, and generate javascript output which calls this named function passing the data object as its only parameter.Method Detail |
---|
protected com.google.gwt.core.client.JavaScriptObject create(com.google.gwt.core.client.JavaScriptObject config)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |