Passing a DataTable from JavaScript to Java

I am using the client side Google visualization API and I am creating a DataTable. Then I want to transfer it to my server and upload it via the spreadsheet API to the spreadsheet. Probably the best way is to use JSON, so I converted it using the toJSON () method and sent it via POST to my server. I tried using these 2 classes:

Now I noticed that these 2 classes are incompatible, at least not over JSON. The JavaScript class converts, for example, the following:

{"cols":[
         {"id":"Col1","label":"","type":"string"}
         {"id":"Col2","label":"","type":"date"}
        ],
 "rows":[
         {"c":[{"v":"a"},{"v":"Date(2010,10,6)"}]},
         {"c":[{"v":"b"},{"v":"Date(2010,10,7)"}]}
        ]
}

But on the Java DataTable side, there are different names for the parameters, and I use Gson, which has different type values:

cols -> columns
c -> cells
v -> value

type:"string" -> type:"TEXT"
type:"number" -> type:"NUMBER"

And I'm afraid there is even more incompatibility.

So how can I convert a JavaScript DataTable to a Java DataTable?

+5
2

. , DataTable Java Datasource Javascript DataTable API Google.

Java Data Data DataTable JsonRenderer, . , , . , .

@WebService
@Path("/tables")
public class DataManager extends GenericManager<db, Long> {

    @Path("/hello/")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public DataTable getDataTable() {
        DataTable data = new DataTable();
        ... populate object ...
        return data;
    } 

Java DataTable, , API- API Google javascript DataTable. GVis.

Java JsonRenderer (. Google Groups), Json- .

    @Path("/hello/")
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getDataTable() {
        DataTable data = new DataTable();
        CharSequence charSequence = JsonRenderer.renderDataTable(dataTable, true, true);
        return charSequence.toString();
    } 

Javascript, , (. Google Group):

jQuery.ajax({
    context: this,
    type: 'Get',
    url: url,
    success: function(data) {
         var args = eval('('+data+')');  // add parens around the returned string                          
         var dataTable = new google.visualization.DataTable(args);  
         ...
 });

DataTable Java Datasource.   ,

+2

, python GWT DataTable . google-visualization-python api DataTable.
:

DataTable dataTable = DataTable.create(JSONParser.parseLenient(data).isObject().getJavaScriptObject());

DataTable JSON json- localStorage json .

GWT DataTable - , Javascript DataTable JSNI. , .

, gwt-visualization API (1.1.2)?

0

All Articles