PDA

View Full Version : [CLOSED] AggregationRowConfig with RPC return null pointer



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

fother
17 Jun 2009, 6:58 AM
in ColumnFooter you need verify in the line 228

add this condition



if (value != null) {
Object obj = renderer.render(value, j, (Grid) grid, (ListStore) store);
}

fother
17 Jun 2009, 7:00 AM
other real situation.. the RPC need access other database.. that delay more than normal..

sven
17 Jun 2009, 7:03 AM
The issue is in your renderer and not GXT. I close this issue.

fother
17 Jun 2009, 7:36 AM
no!

to solve this I always need add this condition in my code..



totals.setRenderer("age", new AggregationRenderer<BeanModel>() {

public Object render(Number value, int colIndex, Grid<BeanModel> grid, ListStore<BeanModel> store) {

if (value != null) {
return NumberFormat.getCurrencyFormat().format(value.doubleValue());
} else {
return "";
}
}
});

sven
17 Jun 2009, 7:37 AM
yes and that is correct. If value is null you cant call doubleValue on it.

fother
17 Jun 2009, 7:40 AM
yes I know about this :D

the problem that this method is called twice.. when the grid is render.. that the value is null and when the data its load.. I believe that if the value is null, cannot call the method render.. because in all situation will return null pointer..

sven
17 Jun 2009, 7:41 AM
Also that is correct. The footer should also be displayed with 0 records in the grid.

fother
17 Jun 2009, 7:44 AM
I agree with you.. but only the html and widget can be render when have 0 records..

the method render no can.. because what the value for average sum and other when dont have records?

sven
17 Jun 2009, 7:46 AM
That is why you define a renderer. So you can say what should be displayed in that case.

fother
17 Jun 2009, 7:49 AM
I agree with you again...

but if I dont define the render.. the value of my sum or average wont appears.. its other issue?

so if I always need define the render.. if my value (sum average or other) its null.. isn important for me.. so dont show nothing

sven
17 Jun 2009, 7:50 AM
The thing you describe now is already fixed in SVN, but it is not linked to the NPE you get from your code of your firstpost.

fother
17 Jun 2009, 7:57 AM
The thing you describe now is already fixed in SVN
good


but it is not linked to the NPE you get from your code of your firstpost.

sorry I dont understand.. and the translator dont help me

sven
17 Jun 2009, 7:58 AM
This issue you descriped in your last post is not linked to the one you descriped in your first post.

fother
17 Jun 2009, 8:01 AM
yes, I know I just mentioned ;)

the method render is called only when its used for AVG, SUM?

fother
17 Jun 2009, 8:05 AM
if its true.. I dont need called the method render that I implement if my value is null :D