I am perhaps about to make you all cringe... I am still a java and GET
newbie, but that is not the cringing part. I would like to use the
new
CellTable widget but the exapmles I see all end up using servlets for
asyc data gathering calls.
I do not have access to Tomcat or other servlet containers. Assume
that I only have old school RequestBuilder access to CGI scripts. Is
it possible to hook the "AsyncCallback" to RequestBuilder?
Here is an example of where I am now:
///////////////////
package itg.admin_communications_news.client;
import java.util.Arrays;
public class NewsList
extends Composite {
static public void LOG(String msg) {
if (RootPanel.get("messages").getWidgetCount() == 0) {
RootPanel.get("messages").add(new HTML("<h3>Messages</
h3>"));
}
RootPanel.get("messages").add(
new HTML("<h1>NewsList</h1><pre>" + msg + "</pre>"));
}
final GlassPanel glassPanel = new GlassPanel(false);
FlowPanel panel = new FlowPanel();
private static final List<NewsItem> CONTACTS = Arrays.asList();
CellTable<NewsItem> list = new CellTable<NewsItem>();
public NewsList() {
JSONObject getInfoData = new JSONObject();
initWidget(panel);
getInfoData.put("command", new JSONString("get"));
getInfo(getInfoData);
list.setPageSize(20);
AsyncDataProvider<NewsItem> provider =
new
AsyncDataProvider<NewsItem>() {
@Override
protected void onRangeChanged(HasData<NewsItem> display) {
final int start =
display.getVisibleRange().getStart();
int length = display.getVisibleRange().getLength();
AsyncCallback<List<NewsItem>> callback =
new
AsyncCallback<List<NewsItem>>() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(List<NewsItem> result) {
updateRowData(start, result);
}
};
// The remote service that should be implemented
getInfo(start, length, callback);
}
};
provider.addDataDisplay(list);
provider.updateRowCount(CONTACTS.size(), true);
SimplePager pager = new SimplePager();
pager.setDisplay(list);
panel.add(pager);
panel.add(list);
}
private void getInfo(int pageStart, int pageLength,
AsyncCallback<List<NewsItem>> callback) {
String requestData = "Command=get&"+
"Start=" + pageStart + "&" +
"Length=" + pageLength + "&";
RequestBuilder req;
String key = "";
final JSONObject controls = new JSONObject();
LOG("getInfo: a");
req = new RequestBuilder(RequestBuilder.POST,
URL.encode(GWT.getHostPageBaseURL() +
"news.cgi"));
req.setRequestData(URL.encode(requestData));
req.setHeader("Content-Type", "application/x-www-form-
urlencoded");
req.setCallback(new RequestCallback() {
public void onError(Request request, Throwable exception)
{
Window.alert("getInfo failed");
}
public void onResponseReceived(Request request, Response
response) {
try {
JSONObject Info = JSONParser
.parseStrict(response.getText())
.isObject();
LOG("getInfo: d");
if (Info == null) {
throw new RuntimeException("Get info returned
null");
} else if (Info.size() > 0) {
glassPanel.removeFromParent();
if (controls.containsKey("_actionAfter")) {
String value =
controls.get("_actionAfter")
.isString()
.stringValue();
LOG("getInfo: d 1:value=" + value);
if (value.equals("clearForm")) {
form.reset();
} else {
Window.alert("Unknown after-action: "
+ value);
}
}
} else {
Window.alert("No items to display");
}
} catch (JSONException e) {
throw new RuntimeException("Failed to send JSON
request");
}
}
});
try {
RootPanel.get().add(glassPanel, 0, 0);
req.send();
} catch (RequestException e) {
e.printStackTrace();
}
LOG("getInfo: e");
}
}
///////////////////
The thnig is that I do not know haow to signal "provider" that there
is new data.
I see the "callback" parameter to "getInfo" but I'm not sure how to
use it to make that singnal... assuming I am supposed to use it.
Is using plain RPC to do this just too strange?
--
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.