I'm trying to create a fairly simply GWT app using the GXT framework, and am doing this based on the eBook "Ext GWT 2.0 Beginners Guide". It details all the step for building an app using GXTs MVC model, and most of it is working as expected, however I can not - for the life of it - add new rows to my Grid.
The initial loading of the Grid data (through itemStore, loader, and an RPCProxy work correct).
However every time I fire the event that triggers adding a new row, the ListStore to which I want to add, is empty (not null! but empty) - even though my Grid is showing data after the initial load!
Here is some of the relevant code:
public class MessageGrid extends LayoutContainer {
private final Grid<ModelData> grid;
private final ListLoader<ListLoadResult<MarketingMessage>> loader;
private final ListStore<ModelData> itemStore;
public MessageGrid() {
setLayout(new FitLayout());
final MarketingServiceAsync marketingService = Registry.get(MarketingUIConstants.MARKETING_SERVICE);
RpcProxy<List<MarketingMessage>> proxy = new RpcProxy<List<MarketingMessage>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<List<MarketingMessage>> callback) {
marketingService.getMessages(callback);
}
};
final List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("col1", "Name", 100));
columns.add(new ColumnConfig("col2", "Phone", 100));
final ColumnModel columnModel = new ColumnModel(columns);
loader = new BaseListLoader<ListLoadResult<MarketingMessage>>(proxy);
itemStore = new ListStore<ModelData>(loader);
grid = new Grid<ModelData>(itemStore, columnModel);
grid.setBorders(true);
grid.setAutoExpandColumn("sentTime");
grid.setAutoHeight(false);
grid.setHeight("100%");
}
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
loader.load();
add(grid);
}
public void addMessage(MarketingMessage marketingMessage) {
itemStore.add(new MarketingMessage("test", "test")));
}
}
addMessage() is being called by the owning component (a View to which this LayoutContainer has been added).
If I set a breakpoint inside the addMessage() method, my itemStore has size 0 (same goes for grid.getStore() for that matter).
I've tried various different changes to this code and I have yet to see a row being added.
On a similar note: if inside the addMessage() method I try to do a reload from the proxy - since I do update the server side data as well - ie. loader.load(), it also does not have any visible effect.