If the servlet is returning json then wouldn't just calling eval(jsonString) in your client create the javascript objects?
On Tue, Oct 26, 2010 at 9:42 AM, Subhrajyoti Moitra <[email protected]>wrote: > IMHO Overlay types are so much better than this round about solution. > > WHy cant your servlet just output JSON data instead of some script? > > What you are doing manually, would have been done automatically if u used > Overlay types. > > Anyways, good you were able to sort this problem out. > > Thanks, > Subhro. > > > On Tue, Oct 26, 2010 at 7:08 PM, Santosh kumar <[email protected]> wrote: > >> Hi , >> >> Moitra and Thomas >> >> Thanks for your reply.. !! >> >> Anyways i got a solution.. >> >> *use this code in the servlet* --- >> - get the list of products (productList) and use it in the servlet: >> - This is JSON format to form a array of objects >> >> // Open the <script> tag >> writer.append("<script type=\"text/javascript\">"); >> writer.append("var product="); >> writer.append("{productList: '["); >> >> Iterator<Product> iter = productList.iterator(); >> while (iter.hasNext()) { >> Product product= iter.next(); >> writer.append("{productName: \"" + Product .getProductName() + >> "\", id: " + Product .getId() + >> ", productDetails: \"" + Product .getProductDetails() >> + >> ................................. >> ................................. >> "\"}"); >> if (iter.hasNext()) { >> writer.append(","); >> } >> } >> >> // End the <script> tag >> writer.append("]'}; </script>"); >> >> >> *use this code in the GWT onModule *--- >> - call the above servlet on onModule >> >> Dictionary product= Dictionary.getDictionary("product"); >> String productListStr = product.get("productList").toString(); >> JSONArray productJSONArray = JSONParser.parse(productListStr >> ).isArray(); >> List<Product> ProductList = new ArrayList<Product>(); >> for (int i = 0; i < productJSONArray .size(); i++) { >> JSONObject productJSONObject = (JSONObject)productJSONArray >> .get(i); >> Product product= new Product(); >> >> JSONString productNameJSONString = productJSONObject >> .get("productName").isString(); >> product.setProductName(productNameJSONString .stringValue()); >> >> product.setId(Long.valueOf(productJSONObject >> .get("id").toString())); >> >> ......................... >> ......................... >> >> ProductList .add(product); >> } >> >> finally we will get a list of objects. i.e, ProductList . >> >> Guys its really cool concept .. !! enjoy it !! :-) >> >> On Sat, Oct 23, 2010 at 7:21 PM, Subhrajyoti Moitra < >> [email protected]> wrote: >> >>> >>> http://googlewebtoolkit.blogspot.com/2008/08/getting-to-really-know-gwt-part-2.htm >>> >>> Use overlay types to read JSON arrays and objects. >>> >>> Thanks, >>> Subhro. >>> >>> On Sat, Oct 23, 2010 at 11:08 AM, Santosh kumar <[email protected]>wrote: >>> >>>> Hi, >>>> >>>> Using Dictionary in Gwt onModule load i want to get the list of objects >>>> from Json ??? >>>> >>>> http://code.google.com/webtoolkit/articles/dynamic_host_page.html >>>> >>>> The example in the above link it is shown for string, but i want to get >>>> the list of objects form the json ?? >>>> And also can you send me the sample code of JSON format for the list of >>>> objects(same as shown in the above example) >>>> and also how to retrieve these objects in the gwt using Dictionary ? >>>> >>>> please can anyone guide me ? >>>> >>>> -- >>>> Thanks & Regards >>>> >>>> *S a n t o s h k u m a r . k* >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Google Web Toolkit" group. >>>> To post to this group, send email to >>>> [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]<google-web-toolkit%[email protected]> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/google-web-toolkit?hl=en. >>>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Google Web Toolkit" group. >>> To post to this group, send email to [email protected] >>> . >>> To unsubscribe from this group, send email to >>> [email protected]<google-web-toolkit%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/google-web-toolkit?hl=en. >>> >> >> >> >> -- >> Thanks & Regards >> >> *S a n t o s h k u m a r . k* >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Google Web Toolkit" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<google-web-toolkit%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-web-toolkit?hl=en. >> > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-web-toolkit%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > -- Jeff -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected]. 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.
