smartGWTデータソースがこのURLを呼び出す場合:
http://www.smartclient.com/smartgwt/showcase/data/dataIntegration/json/contactsData.js
(データソースがJavaアプリを呼び出している場合は、この回答の下部に移動してください)
データソースが行うリクエストには、次のようなコールバックと呼ばれるGETパラメータが含まれます。
callback=isc.Comm._scriptIncludeReply_0
スクリプトcontactsData.jsは、このGETパラメーターをキャプチャする必要があります。
contactData.jsには、URLからパラメーターを取得するためのライブラリを含める必要があります。
javascriptパラメータ取得機能:
function getParameter ( queryString, parameterName ) {
// Add "=" to the parameter name (i.e. parameterName=value)
var parameterName = parameterName + "=";
if ( queryString.length > 0 ) {
// Find the beginning of the string
begin = queryString.indexOf ( parameterName );
// If the parameter name is not found, skip it, otherwise return the value
if ( begin != -1 ) {
// Add the length (integer) to the beginning
begin += parameterName.length;
// Multiple parameters are separated by the "&" sign
end = queryString.indexOf ( "&" , begin );
if ( end == -1 ) {
end = queryString.length
}
jQueryのパラメーター取得機能
http://ajaxcssblog.com/jquery/url-read-request-variables/
コールバックパラメーターの値を取得したら、次のように、応答の本文にパラメーターとしてJSONを使用して関数名を記述します。
isc.Comm._scriptIncludeReply_0({"item": [ {"id": "1","name": "Monkey"},
{"id": "2","name": "Tree"},
{"id": "3","name": "Banana"} ] })
したがって、javascriptコードは次のようになります。
Response.Write(getParameter(URLrequestFromDatasourceString,"callback") + " ( " + JSON + " )" );
JAVA
smartGWTデータソースがJavaアプリのURLを呼び出す場合:
http://www.smartclient.com/getJson.htm
Javaコントローラーも同じことをしますが、はるかに簡単です
String callbackString = request.getParameter("callback");
response.setContentType("text/X-JSON");
response.getWriter().write( callbackString + " ( " + JSONstring + " ) " );
response.setStatus(HttpServletResponse.SC_OK);
また、この問題に関するブログ投稿へのリンクもあります