Hey people,
I'm not sure if I understand this correctly and figured I could use
some help. I have an existing Java Struts based application that I'm
trying to integrate GWT as a module into. I created some simple client
code and wanted to make a call to the server side to see if it would
work fine. I was able to make a simple HTTP call and return and
display a string of data. Of course, the real world needs more
complicated data. I was reading about JSON to transferring objects and
figured I could use it.

1) now my first question/doubt is whether I'm using it right. From the
GWT docs reading it seemed like I should be sending a string of data
encoded as a JSON object/array and then process that at the client
side and display the information accordingly. So I did the following
to my server side class

import import com.google.gwt.json.client.*;

public class ..... {

public void method1(........)
{
  ....retrieve data from backend.....returns a list of objects

  // to send data back to client //

JSONArray jsonArray = new JSONArray();

int index = 0;

while(iterator.hasNext())
{
  String s1 = list.next().getValue();
  String s2 = list.next().getAnotherValue();

  JSONObject jsonObject = new JSONObject();
  jsonObject.put("key1", JSONParser.parse(s1));
  jsonObject.put("key2", JSONParser.parse(s2));
  jsonArray.set(index++, jsonObject);
}

        response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        response.getWriter().write(jsonArray.toString());
}


I see that this doesn't work and returns a 500 error back instead of
an expected response. Upon further investigation I saw that the code
kept failing right at the moment the JSONArray declaration is reached.
It compiles fine though.

My questions are

a) Is this a valid approach to how JSON is to be used within the GWT
toolkit and Java back end? If yes, what is wrong, if not what is the
correct solution to the problem?

b) On a different note, I was also reading about RPC and about the
serializable types that it would pass across and so on. I use XmlBeans
and figured I could just as well use the bean (or a collection of
beans) and pass it to the client using RPC calls where it would be
processed. Is that even possible?

Thanks

Suri
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to