sgt
30 Jun 2009, 10:53 AM
I have a Grid problem which is probably due to my misunderstanding of how Grids must be populated. I have more or less based this on examples I have found, but it is not working:
public CustSearchGrid (
String name, String address, String phonenumber,
String ageGroup, Date fromDate, Date toDate )
{
setLayout(new FlowLayout(0));
// Create the list of columns for the model
List<ColumnConfig> cols = new ArrayList<ColumnConfig>();
cols.add(new ColumnConfig("name", "Name", 40));
cols.add(new ColumnConfig("address", "Address", 40));
cols.add(new ColumnConfig("phonenumber", "Cell Number", 20));
ColumnModel cModel = new ColumnModel(cols);
ModelType modelType = new ModelType();
modelType.setRoot("rows");
modelType.setRecordName("name");
modelType.setTotalName("total");
modelType.addField("name");
modelType.addField("address");
modelType.addField("phonenumber");
// RequestBuilder
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode("/searchCustomers"));
String reqData = createRequestList(name, address, phonenumber, ageGroup, fromDate, toDate).toString(); // This gives JSON string such as: "['namehere', 'addr', '12313123', '26-49', 'Wed Jun 10 00:00:00 SAST 2009', 'Tue Jun 30 00:00:00 SAST 2009']"
builder.setRequestData(reqData);
try {
builder.setCallback (
new RequestCallback(){
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
Window.alert("Got error from req: " + request.toString());
}
@Override
public void onResponseReceived(Request request, Response response) {
// TODO Auto-generated method stub
}});
} catch (NullPointerException e) {
}
HttpProxy<String> proxy = new HttpProxy<String>(builder);
JsonReader<PagingLoadConfig> jsonReader = new JsonReader<PagingLoadConfig>(modelType);
final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, jsonReader);
ListStore<ModelData> store = new ListStore<ModelData>(loader);
final Grid<ModelData> grid = new Grid<ModelData>(store, cModel);
grid.setBorders(false);
grid.setHeight("255px");
ContentPanel panel = new ContentPanel();
panel.setFrame(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setHeaderVisible(false);
panel.setBodyBorder(false);
panel.add(grid);
GridView v = new GridView();
v.setEmptyText("Found no results");
v.setForceFit(true);
grid.setView(v);
loader.load();
add(panel);
}
Upon a button being pressed, I instantiate the CustSearchGrid class and it connects to the HTTP web service
It then POSTs "sortField=null&sortDir=NONE" and nothing else. I want it to post my JSON string.
If I force the web service to return e.g. {'total': '1', "rows":[{"name":'John', "address":'No address', "phonenumber":'1234'}]} then it does update the grid.
What am I not understanding correctly? I see there is a book about EXT-GWT on Apress, and I'm going to order it ASAP, but it would be extremely helpful to get through this little problem first.
Thanks!
public CustSearchGrid (
String name, String address, String phonenumber,
String ageGroup, Date fromDate, Date toDate )
{
setLayout(new FlowLayout(0));
// Create the list of columns for the model
List<ColumnConfig> cols = new ArrayList<ColumnConfig>();
cols.add(new ColumnConfig("name", "Name", 40));
cols.add(new ColumnConfig("address", "Address", 40));
cols.add(new ColumnConfig("phonenumber", "Cell Number", 20));
ColumnModel cModel = new ColumnModel(cols);
ModelType modelType = new ModelType();
modelType.setRoot("rows");
modelType.setRecordName("name");
modelType.setTotalName("total");
modelType.addField("name");
modelType.addField("address");
modelType.addField("phonenumber");
// RequestBuilder
RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, URL.encode("/searchCustomers"));
String reqData = createRequestList(name, address, phonenumber, ageGroup, fromDate, toDate).toString(); // This gives JSON string such as: "['namehere', 'addr', '12313123', '26-49', 'Wed Jun 10 00:00:00 SAST 2009', 'Tue Jun 30 00:00:00 SAST 2009']"
builder.setRequestData(reqData);
try {
builder.setCallback (
new RequestCallback(){
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
Window.alert("Got error from req: " + request.toString());
}
@Override
public void onResponseReceived(Request request, Response response) {
// TODO Auto-generated method stub
}});
} catch (NullPointerException e) {
}
HttpProxy<String> proxy = new HttpProxy<String>(builder);
JsonReader<PagingLoadConfig> jsonReader = new JsonReader<PagingLoadConfig>(modelType);
final BaseListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, jsonReader);
ListStore<ModelData> store = new ListStore<ModelData>(loader);
final Grid<ModelData> grid = new Grid<ModelData>(store, cModel);
grid.setBorders(false);
grid.setHeight("255px");
ContentPanel panel = new ContentPanel();
panel.setFrame(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setHeaderVisible(false);
panel.setBodyBorder(false);
panel.add(grid);
GridView v = new GridView();
v.setEmptyText("Found no results");
v.setForceFit(true);
grid.setView(v);
loader.load();
add(panel);
}
Upon a button being pressed, I instantiate the CustSearchGrid class and it connects to the HTTP web service
It then POSTs "sortField=null&sortDir=NONE" and nothing else. I want it to post my JSON string.
If I force the web service to return e.g. {'total': '1', "rows":[{"name":'John', "address":'No address', "phonenumber":'1234'}]} then it does update the grid.
What am I not understanding correctly? I see there is a book about EXT-GWT on Apress, and I'm going to order it ASAP, but it would be extremely helpful to get through this little problem first.
Thanks!