Re: Truncated JSON problem using RequestBuilder with WCF rest service

2012-01-23 Thread shahid
Anyone 

On Jan 20, 3:43 pm, shahid shahidza...@gmail.com wrote:
 Using GWT 2.1, I have a WCF web service with a simple interface and I
 am trying to call it using RequestBuilder as follows:

 String url = http://localhost/EmployeeService/Service1.svc/web/
 GetEmployees;
     RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
 URL.encode(url));

     try {
         builder.sendRequest(null, new RequestCallback(){

             @Override
             public void onResponseReceived(Request request,  Response
 response) {
                 if(200 == response.getStatusCode()){
                     GWT.log(response.getText());
                 }
             }

             @Override
             public void onError(Request request, Throwable exception)
 {
                 System.out.println(error= + exception.getMessage());
             }

         });
     }catch(Exception e){
         e.printStackTrace();
     }

 The service returns the following JSON and I have verified that in
 Firebug as well as Fidler:

 [
     {
         Addresses:[
             {
                 Line1:22 High Street,
                 Line2:Bookham
             }],

         Id:2,
         Name:JHGFFF
     },
     {
         Addresses:[
             {
                 Line1:59 Low Street,
                 Line2:Leatherhead
             },
             {
                 Line1:33 No Entry Road,
                 Line2:Fetchem
             }],

         Id:10,
         Name:Done It
     }
 ]

 However when I look at the response.getText() it truncates the JSON to
 the following:

 [{Id:2,Name:JHGFFF},{Id:10,Name:Done It}]

 Very weired ??

-- 
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-toolkit@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.



Truncated JSON problem using RequestBuilder with WCF rest service

2012-01-20 Thread shahid
Using GWT 2.1, I have a WCF web service with a simple interface and I
am trying to call it using RequestBuilder as follows:

String url = http://localhost/EmployeeService/Service1.svc/web/
GetEmployees;
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
URL.encode(url));

try {
builder.sendRequest(null, new RequestCallback(){

@Override
public void onResponseReceived(Request request,  Response
response) {
if(200 == response.getStatusCode()){
GWT.log(response.getText());
}
}

@Override
public void onError(Request request, Throwable exception)
{
System.out.println(error= + exception.getMessage());
}

});
}catch(Exception e){
e.printStackTrace();
}

The service returns the following JSON and I have verified that in
Firebug as well as Fidler:

[
{
Addresses:[
{
Line1:22 High Street,
Line2:Bookham
}],

Id:2,
Name:JHGFFF
},
{
Addresses:[
{
Line1:59 Low Street,
Line2:Leatherhead
},
{
Line1:33 No Entry Road,
Line2:Fetchem
}],

Id:10,
Name:Done It
}
]

However when I look at the response.getText() it truncates the JSON to
the following:

[{Id:2,Name:JHGFFF},{Id:10,Name:Done It}]

Very weired ??

-- 
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-toolkit@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.



Re: JSON Problem

2010-07-08 Thread hi...@hiramchirino.com
The easiest way by far is to use RestyGWT

http://restygwt.fusesource.org/documentation/index.html

With it, you just create GWT RPC style service interfaces to access
restful JSON resources.

For example, lets say you want to post some JSON to a URL of /blog/
comments:

{
  author:Hiram,
  website:http://hiramchirino.com;,
  comment:This is my comment.
}

and you expect to get some JSON back that looks like:

{
  comment-id:1234,
  moderated:true
}

The you would create some DTO style classes to give you type safe
access to  the request and response like:

class CommentRequest {
  public String author;
  public String website;
  public String comment;
}

class CommentResponse {
  @Json(name=comment-id)
  public String commentId;
  public boolean moderated;
}

Notice that it can even deal with odd property names like comment-id
which would be very hard to access with js overlays.

Then you then create GWT RPC style service interfaces to access your
URL:

public interface CommentService extends RestService {
@POST @Path(/blog/comments)
public void comment(CommentRequest request,
MethodCallbackCommentResponse callback);
}

You then create an instance use the service interface the same way
that
GWT RPC does it:

CommentService service = GWT.create(CommentService.class);

CommentRequest req = new CommentRequest
req.author = Hiram
req.website = http://hiramchirino.com;
req.comment = This is my comment.

service.comment(req, new MethodCallbackCommentResponse() {
public void onFailure(Method method, Throwable exception) {
Window.alert(Error x:  + exception);
}

public void onSuccess(Method method, CommentResponse response) {
Window.alert(posted comment: +response.commentId);
}
});

Hope that helped.


On Jul 5, 8:01 am, 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.



Re: JSON Problem

2010-07-07 Thread Ahmed Shoeib
hi ,
converting the java object to JSON Done using

SONObject json_obj = new JSONObject();
json_obj.put(Member_Email,new JSONString(symbol));
json_obj.put(Member_type, new JSONString(type));

and send it using post method using RequestBuilder

try {
rb.sendRequest(json_obj.toString(), new 
RequestCallback() {
.
.
.
.
}
}

i need to know how to get this object on the server and convert it to
object again

thanks ,
On Jul 6, 10:36 pm, eggsy84 jimbob...@hotmail.com wrote:
 Hi all,

 (As mentioned on the following 
 post:http://groups.google.com/group/google-web-toolkit/browse_thread/threa...
 )

 With the latest versions of GWT you don't have to use any other
 libraries.

 GWT now comes with something known as Javascript Overlays that you can
 utilise to convert JSON into Objects.

 See here:

 http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsOver...

 Also I have made a bit of a discussion on my blog here:

 http://eggsylife.co.uk/2010/04/22/gwt-2-jsonp-and-javascript-overlays...

 Hope this helps,

 Eggsy

 On Jul 6, 1:44 pm, André Moraes andr...@gmail.com wrote:

  I don't think that the Gson project can be used as a GWT module.

  Looks like it is for pure java development, not GWT development.

  Take a look at:http://code.google.com/p/piriti/

  http://code.google.com/p/piriti/This project is a GWT library that provide
  JSON and XML facilities.

  On Tue, Jul 6, 2010 at 5:22 AM, Ahmed Shoeib
  ahmedelsayed.sho...@gmail.comwrote:

   i face this problem
   how i can fix it

   the problem

   /AdminPanel.java'
           [ERROR] Line 139: No source code is available for type
   com.google.gson.Gson; did you forget to inherit a required module?

   Thanks,
   ahmed shoeib

   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() {

              

Re: JSON Problem

2010-07-07 Thread Thomas Broyer


On 7 juil, 20:47, Ahmed Shoeib ahmedelsayed.sho...@gmail.com wrote:
 hi ,
 converting the java object to JSON Done using

 SONObject json_obj = new JSONObject();
 json_obj.put(Member_Email,new JSONString(symbol));
 json_obj.put(Member_type, new JSONString(type));

 and send it using post method using RequestBuilder

 try {
                                 rb.sendRequest(json_obj.toString(), new 
 RequestCallback() {
 .
 .
 .
 .

 }
 }

 i need to know how to get this object on the server and convert it to
 object again

Using any JSON parser; see http://json.org/ for a list of Java (or
other language) implementations.
Note that GWT 2.1 M1 and M2 include org.json, needed for the
RequestFactory.

-- 
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.



Re: JSON Problem

2010-07-07 Thread Ahmed Shoeib
i don't know how to get the parameter from RequestBuilder

i tried

rb.sendRequest(json_mem=+json_obj.toString(), new RequestCallback()
{

... }

and on ther server
req.getparameter(json_mem) ;

and the result is null

how i can get the parameter in post method

On Jul 7, 11:08 pm, Thomas Broyer t.bro...@gmail.com wrote:
 On 7 juil, 20:47, Ahmed Shoeib ahmedelsayed.sho...@gmail.com wrote:



  hi ,
  converting the java object to JSON Done using

  SONObject json_obj = new JSONObject();
  json_obj.put(Member_Email,new JSONString(symbol));
  json_obj.put(Member_type, new JSONString(type));

  and send it using post method using RequestBuilder

  try {
                                  rb.sendRequest(json_obj.toString(), new 
  RequestCallback() {
  .
  .
  .
  .

  }
  }

  i need to know how to get this object on the server and convert it to
  object again

 Using any JSON parser; seehttp://json.org/for a list of Java (or
 other language) implementations.
 Note that GWT 2.1 M1 and M2 include org.json, needed for the
 RequestFactory.

-- 
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.



Re: JSON Problem

2010-07-06 Thread André Moraes
I don't think that the Gson project can be used as a GWT module.

Looks like it is for pure java development, not GWT development.

Take a look at: http://code.google.com/p/piriti/

http://code.google.com/p/piriti/This project is a GWT library that provide
JSON and XML facilities.

On Tue, Jul 6, 2010 at 5:22 AM, Ahmed Shoeib
ahmedelsayed.sho...@gmail.comwrote:

 i face this problem
 how i can fix it

 the problem



 /AdminPanel.java'
 [ERROR] Line 139: No source code is available for type
 com.google.gson.Gson; did you forget to inherit a required module?


 Thanks,
 ahmed shoeib


 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 

Re: JSON Problem

2010-07-06 Thread eggsy84
Hi all,

(As mentioned on the following post:
http://groups.google.com/group/google-web-toolkit/browse_thread/thread/b7c280baf2375841#
)

With the latest versions of GWT you don't have to use any other
libraries.

GWT now comes with something known as Javascript Overlays that you can
utilise to convert JSON into Objects.

See here:

http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsOverlay.html

Also I have made a bit of a discussion on my blog here:

http://eggsylife.co.uk/2010/04/22/gwt-2-jsonp-and-javascript-overlays-with-jsonprequestbuilder/

Hope this helps,

Eggsy

On Jul 6, 1:44 pm, André Moraes andr...@gmail.com wrote:
 I don't think that the Gson project can be used as a GWT module.

 Looks like it is for pure java development, not GWT development.

 Take a look at:http://code.google.com/p/piriti/

 http://code.google.com/p/piriti/This project is a GWT library that provide
 JSON and XML facilities.

 On Tue, Jul 6, 2010 at 5:22 AM, Ahmed Shoeib
 ahmedelsayed.sho...@gmail.comwrote:



  i face this problem
  how i can fix it

  the problem

  /AdminPanel.java'
          [ERROR] Line 139: No source code is available for type
  com.google.gson.Gson; did you forget to inherit a required module?

  Thanks,
  ahmed shoeib

  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
                                           }
   

JSON Problem

2010-07-05 Thread Ahmed Shoeib
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.



Re: JSON Problem

2010-07-05 Thread André Moraes
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.



Re: JSON Problem

2010-07-05 Thread Ahmed Shoeib
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.



Re: JSON Problem

2010-07-05 Thread André Moraes
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/DevGuideServerCommunication.html#DevGuideHttpRequests
and
http://code.google.com/intl/webtoolkit/webtoolkit/articles/using_gwt_for_json_mashups.html
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.



Re: JSON Problem

2010-07-05 Thread Ahmed Shoeib
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 

Re: JSON Problem

2010-07-05 Thread André Moraes
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

Re: JSON Problem

2010-07-05 Thread Ahmed Shoeib
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);
         }-*/;