gwt json

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

gwt json

Postby Petr » Wed Dec 22, 2010 5:30 am

Hi All.
I create servlet, which create json object.
Code: Select all
public class JSONServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.print("{\n" +
                "  'feed': {\n" +
                "    'entry': [\n" +
                "      {'title': {'type': 'text', '$t': 'Some Text'}},\n" +
                "      {'title': {'type': 'text', '$t': 'Some More Text'}}\n" +
                "    ]\n" +
                "  }\n" +
                "}");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}

and I have small gwt app. it is app reads json, but it no works. What is problem?
Code: Select all
package com.mySampleApplication.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.*;
import com.google.gwt.json.client.*;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.*;

public class MySampleApplication implements EntryPoint {

    public void onModuleLoad() {
        final Button fetchDataButton = new Button("Fetch data");
        fetchDataButton.addStyleName("sendButton");
        final Label label = new Label("test");
        RootPanel.get("slot1").add(fetchDataButton);
        RootPanel.get("slot2").add(label);

        fetchDataButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                System.out.println("log 1");
                fetchDataFromServer();
            }
        });
    }

    private void fetchDataFromServer() {
        try {
            String url = "http://localhost:8080/JSONServlet";
            RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
            rb.setCallback(new RequestCallback() {
                @Override
                public void onResponseReceived(Request request, Response response) {
                    Window.alert(response.getText());
                }
                @Override
                public void onError(Request request, Throwable exception) {
                    Window.alert("Error occurred" + exception.getMessage());
                }
            });
            rb.send();
        }
        catch (RequestException e) {
            Window.alert("Error occurred" + e.getMessage());
        }
    }
}

Thanks.
Petr
 
Posts: 1
Joined: Wed Dec 22, 2010 5:23 am

Re: gwt json

Postby Eric Clayberg » Wed Dec 22, 2010 5:35 am

I would recommend posting general GWT questions to our (Google's) GWT Forum.

We would like to keep this forum focused on GWT Designer itself. Thank you.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests

cron