Hi, I'm new here and new to gwt.
I'm not a Java programmer, but I'm start to learn to use GWT.

I'm trying to use an extension of the ListBox widget to make it able
to collect data from a database by AJAX.

I found only an example on the web, but I obtain an uncaight exception
(class not found) at the first row of this example.

Can you help me? :-)
thanks!

Lorenzo

This is the code:
Note: the error is when it executes the line:

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
source);

ClassNotFoundException
arg0 = com/google/gwt/http/client/RequestBuilder

-----------
package com.myProject.client;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ListBox;

public class JsonListBox extends ListBox {

        public JsonListBox(String source) {

                RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
source);
                try {
                        builder.setCallback(new RequestCallback() {
                                public void onError(Request request, Throwable 
exception) {
                                }

                                public void onResponseReceived(Request request, 
Response response)
{
                                        if (response.getStatusCode() == 200) {

                                                JSONArray items = 
JSONParser.parse(response.getText()).isArray
();

                                                JSONValue jsonValue;

                                                for (int i=0; i<items.size(); 
i++) {
                                                    JSONObject jsMyObject;
                                                    JSONString jsTitle, jsId;

                                                    if ((jsMyObject= 
items.get(i).isObject()) == null) continue;

                                                    if ((jsonValue = 
jsMyObject.get("title")) == null) continue;
                                                    if ((jsTitle= 
jsonValue.isString()) == null) continue;

                                                    if ((jsonValue = 
jsMyObject.get("id")) == null) continue;
                                                    if ((jsId = 
jsonValue.isString()) == null) continue;

                                                    
addItem(jsTitle.stringValue(), jsId.stringValue());

                                                  }

                                                
setVisibleItemCount(items.size());
                                        } else {
                                                
Window.alert(response.getStatusText());
                                        }
                                }
                        });
                        builder.send();
                } catch (Exception e) {
                        Window.alert(e.getMessage());
                }
        }

}

-- 
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.

Reply via email to