Design suggestion using Servlet / java

51 views
Skip to first unread message

Akku

unread,
Jun 11, 2010, 10:42:07 AM6/11/10
to Google Visualization API
Hi friends,
I get the same old json string using DataSourceHelper too.
Please anyone guide me how to process data using a servlet and showing
the chart in a "single event".
I used Requestdispatcher but that seems to be a bad idea.
I used DataSourceHelper.executeDataSourceServletFlow method too, but
get json string on the browser
I am trying to built a website and when the user clicks "go " button
the data should be processed by the servlet and chart should be drawn
by the html code
i am following this tutorial http://code.google.com/apis/visualization/documentation/dev/dsl_get_started.html
need a design suggesion!!!!
Need guidance as to how should i go about it.
I get proper results when i follow the tutorial step by step but donno
how to integrate it.
regards
Akku

Oded Badt

unread,
Jun 11, 2010, 10:55:49 AM6/11/10
to google-visua...@googlegroups.com
Hello Akku

There are generally two approaches to solving such a requirement.
The first is having the "Go" button submit a form whose response is a server side html that is rendered to show a chart
The other is sending an AJAX call and having client javascript code responding to that call draw the chart

What flavor do you prefer?

  Badtnik


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.


Akku

unread,
Jun 11, 2010, 11:52:15 AM6/11/10
to Google Visualization API
Thanks Badtnik,
Can you explain me a bit more please..... i have idea of servlet a bit
but I donno Ajax
Here is what i was doing
When the user clicks "go" i retive some data from it and feed to to
servlet to add the data in the DataTable generateDataTable(Query
query, HttpServletRequest request)

public class Test3 extends HttpServlet implements DataTableGenerator
{......

and call DataSourceHelper.executeDataSourceServletFlow(request,
response, this , isRestrictedAccessMode() );

I noticed that i cant use out.println in this..... it gives me
internal thread exception..... so i didn't used Printer out obj;
The long json string gets created and seen in browser.
I render further using dispatcher to call the html page through the
servlet ......

The Final output that i get on browser in

google.visualization.Query.setResponse({version:'0.6',status:'ok',sig:'1333639331',tab....................
and the entire html code that draws the chart...as it is.....on the
browser
<html>
<head>
<title>Getting Started Example</title>
<!--Load the AJAX API-->
<script type="text/javascript" src="http://www.google.com/jsapi"></
script>
<script type="text/javascript">

//Load the Visualization API and the ready-made Google table
visualization
google.load('visualization', '1', {'packages':
['table']});...................................................................................


This is my code...... when a user hits go
public class Test3 extends HttpServlet implements DataTableGenerator {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
DataSourceHelper.executeDataSourceServletFlow(request, response,
this , isRestrictedAccessMode() );


RequestDispatcher rd;
rd = request.getRequestDispatcher("new.html");
rd.include(request, response);//forward(request, response);

@Override
public Capabilities getCapabilities() {
return Capabilities.NONE;
}


protected boolean isRestrictedAccessMode() {
return false;
}

@Override
public DataTable generateDataTable(Query query, HttpServletRequest
request) {
// Create a data table.
DataTable data = new DataTable();
ArrayList<ColumnDescription> cd = new
ArrayList<ColumnDescription>();
cd.add(new ColumnDescription("name", ValueType.TEXT, "Animal
name"));
cd............................................ ... ...

What should be the approach ??? Or am I doing anything wrong?
The chart draws fine when after running the servlet and getting the
json string on browser . i run the html code manually.

Actually I am taking the data for visualization dynamically so i need
servlet to process it and then call the html page......
A sample code will also be of great help for me.
thanks & regards,
Akku




On Jun 11, 10:55 am, Oded Badt <b...@google.com> wrote:
> Hello Akku
>
> There are generally two approaches to solving such a requirement.
> The first is having the "Go" button submit a form whose response is a server
> side html that is rendered to show a chart
> The other is sending an AJAX call and having client javascript code
> responding to that call draw the chart
>
> What flavor do you prefer?
>
>   Badtnik
>
> On Fri, Jun 11, 2010 at 5:42 PM, Akku <akshayc...@gmail.com> wrote:
> > Hi friends,
> >  I get the same old json string using DataSourceHelper too.
> > Please anyone guide me how to process data using a servlet and showing
> > the chart in a "single event".
> > I used Requestdispatcher but that seems to be a bad idea.
> > I used DataSourceHelper.executeDataSourceServletFlow method too, but
> > get json string on the browser
> > I am trying to built a website and when the user clicks "go " button
> > the data should be processed by the servlet and chart should be drawn
> > by the html code
> > i am following this tutorial
> >http://code.google.com/apis/visualization/documentation/dev/dsl_get_s...
> > need a design suggesion!!!!
> > Need guidance as to how should i go about it.
> > I get proper results when i follow the tutorial step by step but donno
> > how to integrate it.
> > regards
> > Akku
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Visualization API" group.
> > To post to this group, send email to
> > google-visua...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-visualizati...@googlegroups.com<google-visualization-api%2Bunsu...@googlegroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages