fother
17 Jun 2009, 6:51 AM
set the class Customer to
public class Customer implements BeanModelTag, Serializable {
change the code in BeanModelGridExample to
public class BeanModelGridExample extends LayoutContainer {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("padding", "20px");
GridCellRenderer<BeanModel> render = new GridCellRenderer<BeanModel>() {
public Object render(BeanModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BeanModel> store,
Grid<BeanModel> grid) {
return "test " + model.get("age");
}
};
// gwt service
final ExampleServiceAsync service = (ExampleServiceAsync) Registry.get(Examples.SERVICE);
// proxy and reader
RpcProxy<List<Customer>> proxy = new RpcProxy<List<Customer>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<Customer>> callback) {
service.getCustomers(callback);
}
};
BeanModelReader reader = new BeanModelReader();
// loader and store
ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
loader.load();
// column model
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("name", "Name", 200));
columns.add(new ColumnConfig("email", "Email", 100));
ColumnConfig age = new ColumnConfig("age", "Age", 50);
age.setRenderer(render);
columns.add(age);
AggregationRowConfig<BeanModel> totals = new AggregationRowConfig<BeanModel>();
totals.setSummaryType("age", SummaryType.AVG);
totals.setRenderer("age", new AggregationRenderer<BeanModel>() {
public Object render(Number value, int colIndex, Grid<BeanModel> grid, ListStore<BeanModel> store) {
return NumberFormat.getCurrencyFormat().format(value.doubleValue());
}
});
ColumnModel cm = new ColumnModel(columns);
cm.addAggregationRow(totals);
Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
grid.setAutoExpandColumn("name");
grid.setSize(400, 200);
add(grid);
}
on method getCustomers() of the class ExampleServiceImpl, add one break point in
return customers;
DEBUG the GXT explorer demo application and click to see the BeanModelGrid example.. you will see that the grid will render.. and return a null pointer exception.. so.. click in button Resume(F8) the data will render and the aggregation row will appears correctely..
Real situation.. when call a remote procedure.. can be a complex calc and delay more than the normal..
I believe that the behavior of the aggregation row should be like GridCellRenderer
public class Customer implements BeanModelTag, Serializable {
change the code in BeanModelGridExample to
public class BeanModelGridExample extends LayoutContainer {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("padding", "20px");
GridCellRenderer<BeanModel> render = new GridCellRenderer<BeanModel>() {
public Object render(BeanModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<BeanModel> store,
Grid<BeanModel> grid) {
return "test " + model.get("age");
}
};
// gwt service
final ExampleServiceAsync service = (ExampleServiceAsync) Registry.get(Examples.SERVICE);
// proxy and reader
RpcProxy<List<Customer>> proxy = new RpcProxy<List<Customer>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<Customer>> callback) {
service.getCustomers(callback);
}
};
BeanModelReader reader = new BeanModelReader();
// loader and store
ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
loader.load();
// column model
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("name", "Name", 200));
columns.add(new ColumnConfig("email", "Email", 100));
ColumnConfig age = new ColumnConfig("age", "Age", 50);
age.setRenderer(render);
columns.add(age);
AggregationRowConfig<BeanModel> totals = new AggregationRowConfig<BeanModel>();
totals.setSummaryType("age", SummaryType.AVG);
totals.setRenderer("age", new AggregationRenderer<BeanModel>() {
public Object render(Number value, int colIndex, Grid<BeanModel> grid, ListStore<BeanModel> store) {
return NumberFormat.getCurrencyFormat().format(value.doubleValue());
}
});
ColumnModel cm = new ColumnModel(columns);
cm.addAggregationRow(totals);
Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
grid.setAutoExpandColumn("name");
grid.setSize(400, 200);
add(grid);
}
on method getCustomers() of the class ExampleServiceImpl, add one break point in
return customers;
DEBUG the GXT explorer demo application and click to see the BeanModelGrid example.. you will see that the grid will render.. and return a null pointer exception.. so.. click in button Resume(F8) the data will render and the aggregation row will appears correctely..
Real situation.. when call a remote procedure.. can be a complex calc and delay more than the normal..
I believe that the behavior of the aggregation row should be like GridCellRenderer