PDA

View Full Version : [FNR] StoreEvents pass little information in Grid



gslender
10 Aug 2008, 10:10 PM
Hi,

StoreEvents are recieved for events such as Add/DataChanged/Remove/Clear etc..

But, the StoreEvent passed doesn't contain anything usefull to be used by the handlers - ie the model, models and operation's are null.

Was expecting that a listener would recieved notification and a list of items added/removed etc so that it can produce what it needs to update its UI.

The following code demonstrates the issue...


/*
* Ext GWT - Ext for GWT
* Copyright(c) 2007, 2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
package com.extjs.gxt.samples.explorer.client.pages;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.samples.explorer.client.ExplorerServiceAsync;
import com.extjs.gxt.samples.explorer.client.model.Customer;
import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelReader;
import com.extjs.gxt.ui.client.data.ListLoader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Record;
import com.extjs.gxt.ui.client.store.StoreEvent;
import com.extjs.gxt.ui.client.store.StoreListener;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class StoreEventBeanModelGridPage extends LayoutContainer {

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setStyleAttribute("padding", "20px");

// gwt service
final ExplorerServiceAsync service = (ExplorerServiceAsync) Registry.get("service");

// proxy and reader
RpcProxy proxy = new RpcProxy() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
service.getCustomers(callback);
}
};
BeanModelReader reader = new BeanModelReader();

// loader and store
ListLoader loader = new BaseListLoader(proxy, reader);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
store.addStoreListener(new StoreListener<BeanModel>() {
public void handleEvent(StoreEvent<BeanModel> se) {
System.out.println("se.models ="+se.models ); // <<< this is null ??
System.out.println("se.model ="+se.model); // <<< this is null ??
System.out.println("se.operation ="+se.operation); // <<< this is null ??
System.out.println("se.store ="+se.store); // <<< this is store, but not much help - already have store !!
super.handleEvent(se);
}});

loader.load();

// column model
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("name", "Name", 200));
columns.add(new ColumnConfig("email", "Email", 100));
columns.add(new ColumnConfig("age", "Age", 50));
ColumnModel cm = new ColumnModel(columns);

Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
grid.setAutoExpandColumn("name");
grid.setWidth(400);
grid.setAutoHeight(true);
grid.setBorders(true);
grid.addListener(Events.CellClick, new Listener<GridEvent>() {
public void handleEvent(GridEvent gridEvent) {
int rowIndex = gridEvent.rowIndex;
BeanModel model = (BeanModel) gridEvent.grid.getStore().getAt(rowIndex);
Customer customer = (Customer) model.getBean();
System.out.println(customer.getName());

List<Customer> customers = new ArrayList<Customer>();
List<Record> records = gridEvent.grid.getStore().getModifiedRecords();
for (Record r : records) {
BeanModel m = (BeanModel)r.getModel();
customers.add((Customer)m.getBean());
}
}
});






add(grid);
}

}