views:

644

answers:

2

I am trying to follow this tutorial on how to connect to a database in GWT, but instead of creating a login program, I am trying to retrieve a GWT Visulation DataTable from my DB so that I can then create a Annotated TimeLine. I have gotten very far, but I hit the final wall I can't figure out. Unlike the tut, I am not returning a simple User class from the RPC, but a complex DataTable. The problem is that this DataTable must be serializable by GWT standards. Is there any easy way for accomplish this?

I am using a RPC, instead of a Query system for security reasons. I don't want people to by able to look at my javascript and see my queries and such.

Thank you.

UPDATE: After going back to the problem I have found that DataTable is a JavaScriptObject and was probably never meant to be made on the server side. So new question, What is the best way to manually make DataTable into something serlizable and then what is the best way to remake it client side. Thanks Again!

A: 

Ok so I figured it out myself (sorta) so I thought I would post the answer here in case someone else happens to have the same problem later.

The answer in short that is impossible. DataTable is a JSO object, and in GWT current release (1.6something) it can not serialize those types of objects. What I had to do was break down my data into a series of ArrayLists and hold those in a temperay Object. That object can then be serialized and sent to the client side. The problem with this is that you must then construct the DataTable object on the client side.

If anyone else happens to come up with a better idea I would still be interested on finding out.

Thanks.

-Eric

Eric Koslow
A: 

I think you can do it on server side String json = JsonRenderer.renderDataTable(yourDataTable, true, true);

and on client side use some thing like

public static native DataTable toDataTable(String json) /-{ return new $wnd.google.visualization.DataTable(eval("(" + json + ")")); }-/;

I think it should work

hassan