Thanks a lot My Friends it is easy way thanks for your support
On Jul 5, 9:33 pm, André Moraes <andr...@gmail.com> wrote: > The response comes async. > > When the response from the server arrives at the client the method > onResponseReceived in the RequestCallback object is called, if an > error hapens the the onErrormethod is called. > > The RequestCallback object is the second parameter in the sendRequest > function call. > > public void onResponseReceived(Request > request, Response response) > { > if (response.getStatusCode() > == 200 || response.getStatusCode() > == 304) > { > JavaScriptObject > responseData = > JsonHelper.stringToJso(response.getText()).cast()); > // use the response > } > else > { > // invalid response > } > } > @Override > public void onError(Request request, > Throwable exception) { > // error on the resquest > } > }); > > On 5 jul, 15:01, Ahmed Shoeib <ahmedelsayed.sho...@gmail.com> wrote: > > > you told me how to send request from client to server > > > now i want how yo get data from server to use it in client > > > and the data in json > > > On Jul 5, 8:12 pm, André Moraes <andr...@gmail.com> wrote: > > > > This code is quite simple > > > > The line: > > > > re = rb.sendRequest("jsonrpc-call=" + JsonHelper.jsoToString(call), > > > new RequestCallback() > > > > prepare a AJAX call to the server and make your javascript object to a > > > string using JsonHelper.jsoToString. > > > In ther server the json-string will be accessible by the parameter > > > "jsonrpc-call". > > > > The line: > > > > if (response.getStatusCode() > > > == 200 || response.getStatusCode() > > > == 304) > > > { > > > JavaScriptObject > > > responseData = > > > JsonHelper.stringToJso(response.getText()).cast()); > > > // use the response > > > } > > > > get the response wrote by the server and make i availabe as a > > > JavaScriptObject. > > > > You can use the JSONObject class to populate and read a > > > JavaScriptObject. > > > > You can read more about JSON + GWT at: > > > >http://code.google.com/intl/webtoolkit/webtoolkit/doc/latest/DevGuide... > > > andhttp://code.google.com/intl/webtoolkit/webtoolkit/articles/using_gwt_... > > > On 5 jul, 12:50, Ahmed Shoeib <ahmedelsayed.sho...@gmail.com> wrote: > > > > > i want a simple example to describe it > > > > cause i need it as soon as possible > > > > > On Jul 5, 6:18 pm, André Moraes <andr...@gmail.com> wrote: > > > > > > re = rb.sendRequest("jsonrpc-call=" + > > > > > JsonHelper.jsoToString(call), > > > > > new RequestCallback() { > > > > > > @Override > > > > > public void > > > > > onResponseReceived(Request request, Response response) > > > > > { > > > > > if (response.getStatusCode() > > > > > == 200 || response.getStatusCode() > > > > > == 304) > > > > > { > > > > > JavaScriptObject > > > > > responseData = > > > > > JsonHelper.stringToJso(response.getText()).cast()); > > > > > // use the response > > > > > } > > > > > else > > > > > { > > > > > // invalid response > > > > > } > > > > > } > > > > > > @Override > > > > > public void onError(Request request, > > > > > Throwable exception) { > > > > > // error on the resquest > > > > > } > > > > > }); > > > > > > public class JsonHelper { > > > > > > public static String jsoToString(JavaScriptObject jso) { > > > > > if (isJsonLibraryDefined()) { > > > > > return _jsoToString(jso); > > > > > } else { > > > > > return new JSONObject(jso).toString(); > > > > > } > > > > > } > > > > > > public static JavaScriptObject stringToJso(String value) { > > > > > if (isJsonLibraryDefined()) { > > > > > return _stringToJso(value); > > > > > } else { > > > > > return _stringToJsoEval(value); > > > > > } > > > > > } > > > > > > public static native String _jsoToString(JavaScriptObject > > > > > jso) /*-{ > > > > > return JSON.stringify(jso); > > > > > }-*/; > > > > > > public static native JavaScriptObject _stringToJso(String > > > > > string) /*- > > > > > { > > > > > return JSON.parse(string); > > > > > }-*/; > > > > > > public static native JavaScriptObject _stringToJsoEval(String > > > > > string) /*-{ > > > > > return eval("(" + string + ")"); > > > > > }-*/; > > > > > > public static native boolean isJsonLibraryDefined() /*-{ > > > > > return typeof(JSON) != 'undefined' > > > > > && typeof(JSON.parse) != 'undefined' > > > > > && typeof(JSON.stringify) != 'undefined'; > > > > > }-*/; > > > > > > } > > > > > > The JsonHelper class handle the conversion to and from JSON. > > > > > > If possible use the json.org javascript library that implements the > > > > > functions JSON.parse / JSON.stringify > > > > > > I am currently writing a project that encapsulates that library and > > > > > make it more easier to use than this JsonHelper class. > > > > > > When i release it in google-code I let you know. > > > > > > Hope it helps. > > > > > > On 5 jul, 09:01, Ahmed Shoeib <ahmedelsayed.sho...@gmail.com> wrote: > > > > > > > Dear Friends , > > > > > > > i face a problem when trying to send and receive json object between > > > > > > client and server in GWT application > > > > > > > so i want a simple example that show me how to do this > > > > > > > Thanks, > > > > > > ahmed shoeib -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.