PDA

View Full Version : updating a store in a grid



giovanni.puliti
5 Jan 2010, 6:21 AM
hi guys

I'm developing a little GXT demo where i've to show some data fetched from a EJB layer (wrapped with a Business Delegate that run behind a GWT-RPC mechanism).
The application is based on a MVC schema; the main parts are:

- TimeTablePanel, is a panel (i.e. is the GUI where the grid is placed).
- OperationController a controller (intercepting event from the GUI and runnning RPC invocation for the reload of data)
- TutorView, a View that run backside the GUI's Panel.

The organization of the application is very similar to the mail app from GXT example.

This is the flow of the application:
1. first round the grid in TimeTablePanel show "all" the data fetched from the EJB layer via an RPC GXT call. That is ok, i can see all the rows in the grid.
2. the user, using two combo on the TimetablePanel define some parameter to fecth just some data to show in the grid
3. changing the value on the combos fire an event (ie an event named loadLeaves)
4. the controller OperationController intercept this event, and do some data reloading via RPC; the new list of data is placed on a new store
5. the controller embedd the new store in the event and forwrd this event to the view TutorView
6. the TutorView take the store from the event, and bind the store to the grid in the panel TimeTablePanel

i'v no excpetions, no error, no strange message, but at the end of that flow nothing appear in the grid. At step 1 the grid was populated, at 6 was blank

Look: the step 2 is not a refinement of data loaded from 1, it's another loading from EJB, so i cannot use the grid filters. Actually a the first step the grid could be blank, the business rule is the user insert data via the two combos.


i place some line of code to exaplain better:

//////////////////////////////////////////////////////////
STEP 1: in the TimeTablePanel:
//////////////////////////////////////////////////////////
final RemoteProviderAsync remoteProvider = (RemoteProviderAsync) Registry.get("remoteProvider");

RpcProxy proxy = new RpcProxy(){
@Override
public void load(Object loadConfig, AsyncCallback callback) {
remoteProvider.getPresenzeOre(callback);
}
};

BeanModelReader reader = new BeanModelReader();
ListLoader loader = new BaseListLoader(proxy, reader);
store = new ListStore (loader);

loader.addLoadListener(new LoadListener(){
@Override
public void loaderLoadException(LoadEvent le) {
System.out.println("loading error "+le.exception);
}
public void loaderLoad(LoadEvent le) {
System.out.println("Store Loaded: " + store.getCount());

}
});
loader.load();
...
...
grid = new EditorGrid<ModelData>(store, cm);
grid.setBorders(true);
grid.setStripeRows(true);
grid.getView().refresh(true);



//////////////////////////////////////////////////////////
STEP 2-3: in the TimeTablePanel: fire the event at the combo change value
//////////////////////////////////////////////////////////

typesCombo.addSelectionChangedListener(new SelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent se) {
SimpleComboValue value = (SimpleComboValue)se.getSelection().get(0);
String courseType = value.getValue().toString();
Registry.register("timetable.courseType", courseType);
populateDetailCombo(detailCombo, courseType);
AppEvent evt = new AppEvent(AppEvents.loadLeaves);
Dispatcher.forwardEvent(evt);
}
});



//////////////////////////////////////////////////////////
STEP 4-5: in the controller intercepting the event and reload some data
//////////////////////////////////////////////////////////
public void handleEvent(AppEvent event) {
EventType type = event.getType();

if (type == AppEvents.loadLeaves) {
// this method make the RPC call
ListStore store = loadOrePresenze();
AppEvent ae = new AppEvent(AppEvents.viewTimeTable);
event.setData("store", store);
forwardToView(tutorView, event);
}
else if (type == AppEvents.Error) {
onError(event);
}
}

/////////////////////////////////////////////////////////////////////////
STEP 6: in the view getting the store from the event ad bind the new store to the grid
/////////////////////////////////////////////////////////////////////////
protected void handleEvent(AppEvent event) {
...
...

if (event.getType() == AppEvents.loadLeaves) {
System.out.println("gestione dell'evento loadLeaves");
ListStore store = event.getData("store");

if (store != null){
this.timeTablePanel.getStore().removeAll();
this.timeTablePanel.setStore(store);
this.timeTablePanel.getGrid().getView().refresh(true);
this.timeTablePanel.layout();
}
else{
System.out.println("store was null");
}
return;
}

}




The removeAll at step 6 run ok, but anythig else appear inside the grid......

Any idea?


giovanni

micgala
5 Jan 2010, 6:36 AM
Hi.

Next time, use the code tags to wrap your codes. Makes much easier to read.

One suggestion, try to use


this.timeTablePanel.getGrid().reconfigure(store, this.timeTablePanel.getGrid().getColumnModel());

instead of


this.timeTablePanel.setStore(store);

Hopefully that will help you.

Regards,
Michel.

PS: are you sure the new store reference is different from the one you are removing all?
Make sure they are not the same store :)

giovanni.puliti
5 Jan 2010, 9:56 AM
thanx micgala


no, your suggestion doesn't run. but i'm experiencing a strange result in logs.
this is the method in controller responsible for reloading the store:




/*
* carica la lista degli oggetti model corrispondenti alle assenze
* */
protected ListStore loadOrePresenze(){
System.out.println("--- Enter Controller.loadOrePresenze()");

final RemoteProviderAsync remoteProvider = (RemoteProviderAsync) Registry.get("remoteProvider");

RpcProxy proxy = new RpcProxy(){
@Override
public void load(Object loadConfig, AsyncCallback callback) {
remoteProvider.getPresenzeOre(callback);
}
};



BeanModelReader reader = new BeanModelReader();
ListLoader loader = new BaseListLoader(proxy, reader);
ListStore store = new ListStore (loader);

loader.addLoadListener(new LoadListener(){
@Override
public void loaderLoadException(LoadEvent le) {
System.out.println(" loading error "+le.exception);
}
public void loaderLoad(LoadEvent le) {
System.out.println("store reLoaded " + store.getCount()+" elements."); // <-- this print 6 elements are loaded, but it is printed after the execution of the method
}
});

loader.load();
System.out.println("--- Exit Controller.loadOrePresenze() - the store has " + store.getCount()+" elements"); // <-- this print 0 elements are loaded
return store;

}

this is the log output:


--- Enter Controller.loadOrePresenze()
--- Exit Controller.loadOrePresenze() - the store has 0 elements

--- Enter TutorView.handleEvent event type: com.extjs.gxt.ui.client.event.EventType@ab2399
store from event contains 0 elements
loadOrePresenze(): Store contains6 elements.notice on the last line: it's a message printed during the loading operartion inside the loadPresenze() method, but it arrive in the log after the returning of that method..... maybe it's just a log concurrent problem.... but it find 6 elements indedd!!

do i'm completly wrong?

G