View Full Version : Grid Sort - Disabled by Controller-Event
Michi_de
5 Dec 2008, 3:30 AM
Hi,
i've written an application which is using all the MVC classes from ext gwt.
So after a button is clicked, an event is fired, the right controller takes this event and forward it to the right view.
It works very good.
But there is one problem:
After initialization, the "showStatistics" event is fired. The controller forwards it to the "contentView". The content view just do one thing:
private void onShowStatistics(){
LayoutContainer wrapper = (LayoutContainer) Registry.get("center");
wrapper.removeAll();
wrapper.add(statPanel);
wrapper.layout();
}the "statPanel" is a custom widged (extends: ContentPanel).
So i take the "center" LayoutContainer and put the ContentPanel-Subclass into it.
After this initial "showStatistics" event, the statistic panel is shown.
The statistic panel contains a grid (paging grid with a store and toolbar binded).
The grid is working very good. I see all the data and i can sort the data and page through the data.
But now i hit a button, which fires again the "showStatistics" event. Now the same procedure take place.
I still can see the grid and the data. But now every time i try to sort the values, it does the sort twice. It does sort it twice so fast, normaly i wouldnt even know it does. After i watched my log file, i saw it does the sort method twice.
But why? If i click another time on the button, to fire the "showStatistics" event, it still just sort it twice.
If i reload the application and the initial event fires the "showStatistics" event, everything works just fine till i do something, what fires "showStatistics" event one more time.
My ContentView just do the code, i mentioned above. It just take the center, remove all and put the statisticsPanel inside. After it redo this job, the grid's sorting just don't work right anymore.
Any Help?
Michi_de
9 Dec 2008, 12:07 AM
Maybe i didn't have been clear enough in my problem definition? Do you need more information or something, so you can understand my bug/problem better?
Its some really not easy to find bug... as i tried to say, its just very strange. When i first fire the event, my panel with the grid inside gets displayed bug-free. Now i hit a button and the event is fired again, now i still see the panel with the grid but the sort is bugged. Everything is sorted twice (very fast, like the event is just fired twice for some reason).
/edit:
one more thing i found, which is bugged when i refired my event:
i cant resize the rows anymore.
What is the thing, which makes my panel-with-grid bugged? :/
gslender
9 Dec 2008, 3:26 AM
Very hard to say without seeing the full code. Try breaking the app into smaller bits and test each part individually to ensure each is working 100%.
Michi_de
9 Dec 2008, 3:33 AM
Well its realy not that much code, used after the event is fired.
-hit button
-event is fired
-controller catch the event, use "forwardToView(view, event)"
-the view procede the code i mentioned above
thats it.
Well here is my code for the ContentPanel, which is what i add into the "wrapper":
see a picture of this widget below..
public class StatisticsPanel extends ContentPanel {
private Grid<Statistic> buGrid , vhGrid;
private ArrayList<ColumnConfig> buConfigs, vhConfigs;
private ColumnConfig buColumn, vhColumn;
private ColumnModel buColumnmodel, vhColumnModel;
private Text buStatisticsHeader, vhStatisticsHeader;
public StatisticsPanel (ListStore<Statistic> statisticStore, ListStore<Statistic> statVHStore) {
setBodyBorder(true);
setFrame(true);
setHeading("Statistics");
setButtonAlign(HorizontalAlignment.CENTER);
setLayout(new FlowLayout());
setSize((Integer)Registry.get("AppWidth"),450);
buConfigs = new ArrayList<ColumnConfig>();
buColumn = new ColumnConfig();
buColumn.setId("name");
buColumn.setHeader("Business Unit");
buColumn.setWidth(25);
buConfigs.add(buColumn);
buColumn = new ColumnConfig();
buColumn.setId("counter");
buColumn.setHeader("Quantity");
buColumn.setWidth(50);
buConfigs.add(buColumn);
buColumnmodel = new ColumnModel(buConfigs);
buGrid = new Grid<Statistic>(statisticStore, buColumnmodel);
buGrid.setStyleAttribute("borderTop", "none");
buGrid.setHeight(200);
buGrid.setAutoExpandColumn("name");
buGrid.setBorders(true);
buGrid.addListener(Events.CellDoubleClick, new Listener<GridEvent>(){
public void handleEvent(GridEvent be) {
Dispatcher.get().dispatch(AppEvents.BUSearch);
}
});
vhConfigs = new ArrayList<ColumnConfig>();
vhColumn = new ColumnConfig();
vhColumn.setId("name");
vhColumn.setHeader("Virtual Host");
vhColumn.setWidth(210);
vhConfigs.add(vhColumn);
vhColumn = new ColumnConfig();
vhColumn.setId("counter");
vhColumn.setHeader("Quantity");
vhColumn.setWidth(50);
vhConfigs.add(vhColumn);
vhColumnModel = new ColumnModel(vhConfigs);
vhGrid = new Grid<Statistic>(statVHStore, vhColumnModel);
vhGrid.setStyleAttribute("borderTop", "none");
vhGrid.setHeight(200);
vhGrid.setAutoExpandColumn("name");
vhGrid.setBorders(true);
vhGrid.addListener(Events.CellDoubleClick, new Listener<GridEvent>(){
public void handleEvent(GridEvent be) {
Dispatcher.get().dispatch(AppEvents.VHSearch);
}
});
buStatisticsHeader = new Text("Shortcuts by Business Units");
vhStatisticsHeader = new Text("Shortcuts by Virtual Hosts");
add(buStatisticsHeader);
add(buGrid);
add(vhStatisticsHeader);
add(vhGrid);
}
Michi_de
10 Dec 2008, 7:11 AM
Here is more code, maybe this helps?
Everytime the sort event is fired, the store gets reloaded, this is what my servlet does to get the store loaded:
The sort thingy is pretty much the same i saw in the gxt mail example... is here any bug?
public PagingLoadResult<Statistic> getBUStatistics(PagingLoadConfig config) {
DBQuery query = new DBQuery();
List<Statistic> statList = query.getBUStatisticList();
if (config.getSortInfo().getSortField() != null) {
final String sortField = config.getSortInfo().getSortField();
if (sortField != null) {
Collections.sort(statList, config.getSortInfo().getSortDir().comparator(new Comparator<Object>() {
public int compare(Object o1, Object o2) {
Statistic p1 = (Statistic) o1;
Statistic p2 = (Statistic) o2;
if (sortField.equals("name")) {
return p1.getName().compareTo(p2.getName());
} else if (sortField.equals("counter")) {
return ((Integer)p1.getCounter()).compareTo((Integer)(p2.getCounter()));
}
return 0;
}
}));
}
}
ArrayList<Statistic> sublist = new ArrayList<Statistic>();
int start = config.getOffset();
int limit = statList.size();
if (config.getLimit() > 0) {
limit = Math.min(start + config.getLimit(), limit);
}
for (int i = config.getOffset(); i < limit; i++) {
sublist.add(statList.get(i));
}
return new BasePagingLoadResult<Statistic>(sublist, config.getOffset(), statList.size());
}
Michi_de
11 Dec 2008, 12:30 AM
And this is how my store list is binded (initialize() method in controller)
statStoreProxy = new RpcProxy() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
service.getBUStatistics((PagingLoadConfig) loadConfig, callback);
}
};
statStoreLoader = new BasePagingLoader(statStoreProxy);
statStoreLoader.setRemoteSort(true);
statStoreLoader.load();
statStore = new ListStore<Statistic>(statStoreLoader);
So this is all the code i can imagine, what is related to this problem. Nobody see any false statement or sthg? Any bug? Any failure in my coding? =C
gslender
11 Dec 2008, 12:55 AM
I don't understand what bit isn't working... reading through everything you've given and said, it isn't clear what exactly is the problem. You mention clicking a button, but there is no button in your code. Are you talking about double-clicking the cells? in which case where is the event code that is being executed???
Please take the time to explain yourself better.
Michi_de
11 Dec 2008, 1:12 AM
Ok, this is how my application works:
I load the application, the controllers and views get initialized. The stores i need get loaded (one of them is the statisticsStore, the code is mentioned above - the rpc proxy code). Then the views get initialized, which initial all the widgets i need. For example the statistics Panel widged (code mentioned above). The statistics Panel constructor get the store data.
After the initialisation of my application, the "showStatistics" event is fired.
Now the controller gets the event and forward it to the "content view". The content view wrapps the center, remove all widgets which are actually in the center and put the statistics Panel widget inside. (code mentioned above - the wrapper code in the first posting)
Now my application is stable. I see the statistics panel with my data i want it to show. I can click on any column in order to sort by this value. It works fine.
Now there is a button in my application. This button is in the "header panel" widget. I click on this button. The "show Statistics" event is fired again.
Now the same procedure starts, as mentioned above. Actually: i again get my center cleaned by all widgets (the wrapper code in the initial code) and then put the statistics panel into the wrapper.
Now i will see the statistics panel again. But when i click on any column, in order to sort, the sort does not work propper anymore. It just make the sorting twice. If its a int column, it will first sort it by low to high and then high to low just one sort after each other. It sorts so fast, i dont see any change in my statistics panel. But when i take a look into my log file, i see that the servlets method is used twice (see the sort code above).
I also cant resize the columns width anymore.
If its not in hosted mode, i can click on the web browsers "reload" button and the application is loaded a new. Now the statistics works again, because the application got completely reloaded and initialized by new. Now its just the same as above: when i click on the button in the header, to fire the "show statistics" event, the statistics grid will be broken again.
Hope this was clear enough?
gslender
11 Dec 2008, 1:16 AM
the original gird is not unloaded from the store.... call grid.reconfigure(null) to ensure the old grid is unbound from the store... the reload/sort etc might be messing things up.
Michi_de
11 Dec 2008, 1:26 AM
After i click the "show statistics"-button, the grid is not initialized again. The statistics panel widged instance is just put out of the wrapper (wrapper.removeAll() ) and then put again into the wrapper (wrapper.add(statPanel)).
The store, which is bind to the grid inside the statPanel, is just being reloaded again and again (statLoader.load()).
You see?
statStoreProxy = new RpcProxy() {
@Override
public void load(Object loadConfig, AsyncCallback callback) {
service.getBUStatistics((PagingLoadConfig) loadConfig, callback);
}
};
statStoreLoader = new BasePagingLoader(statStoreProxy);
statStoreLoader.setRemoteSort(true);
statStoreLoader.load();
statStore = new ListStore<Statistic>(statStoreLoader);
the statStore i give my statistic panel widget in my intialize() method. This method is only used once: in the initialization.
When the show statistics event is fired, i just get the stat panel and put it into the center layoutcontainer (wrapper) and thats it.
So how i should unbind the store, everytime i put my statistics panel into "foreground"?
gslender
11 Dec 2008, 1:30 AM
I'm saying that just removing the grid object from the panel does not disconnect the old grid from the store - you will end up having two grids etc. either don't remove it, or correctly remove it... either way you need to do it correctly.
Michi_de
11 Dec 2008, 1:41 AM
Thanks so far, for your pattience :)
Still i couldn't solve the problem, this is how i tried it:
private void onShowStatistics(){
LayoutContainer wrapper = (LayoutContainer) Registry.get("center");
wrapper.removeAll();
statPanel.rebind();
wrapper.add(statPanel);
wrapper.layout();
}Now the statPanel widgets ".rebind()" method is called after removing.
This is what the method does:
public void rebind(){
buGrid.reconfigure(statisticStore, buColumnmodel);
}
The statisticStore is the same, as the one the constructor get. The columnmodel is the one of the constructor too.
Nothing actually changed in my problem. The sorting problem continues... :(
/edit:
ah, wait wait wait, i think u missunderstood something: the "center" layout container "wrapper" do not remove the grid from the statistics panel. It removes the statistics panel from the layout container. This "center" layout container is registered in my Registry.get("center"). This happens in the initialization. The layout container just change the content in the "center".
gslender
11 Dec 2008, 1:52 AM
grid.reconfigure(null)
Michi_de
11 Dec 2008, 1:57 AM
Sorry, but
The method reconfigure(ListStore<Statistic>, ColumnModel) in the type Grid<Statistic> is not applicable for the arguments (null)
And when i do grid.reconfigure(null, null) it gets even worse: i get null pointer exception in initialization. My grids both do not get loaded at all.
gslender
11 Dec 2008, 2:14 AM
Michi_de,
I'm sorry but I don't see what you are trying to do vs what you are expecting to happen. You asked previously how to disconnect the store - reconfigure(null,null) etc does this... and if you do this after you init the grid, then yes it will NPE... so I'm not sure what you are trying to do with this removing and adding panel - not sure what goal or objective you are trying to achieve and so I'm not sure what isn't working.
Also, there are bits of the app missing, and you know that, so I can't check every aspect of the code to understand what is going on... sorry I can't help further.
Michi_de
11 Dec 2008, 2:23 AM
Well here are some samples, i realy hope u will understand then, what my application does.
The wrapper removes all panels, in order to display another. In this layout container i can have all my widgets put in. The content of this "center" or "wrapper" is defined by the fired event.
One of the events can be "show statistics" (fired when clicked the "home" text).
Another could be "create shortcut" (fired when clicked on "create shortcut" text).
Every time one of this events are fired, the controller forward it to the view. The view get the wrapper (out of the registry) and .removeAll() (statistics panel, create panel, whatever panel) and put the panel which i asked for inside with .add(my panel).
Here are some pictures, so u hopefully understand :(
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.