PDA

View Full Version : Double refresh of grid



zeroed
15 Aug 2011, 1:37 PM
Hi,

I have a strange problem with GXT. GXT is gxt-2.2.3-gwt22.jar

I have a grid and a button that refreshes this grid (see the source code below).

The problem is that after I refresh a grid it gets frozen. I can't select anything on it. Actually the data is also not refreshing, I see the old data.

But when I press it second time - everything works fine!

And it happens always - I need to make double-refresh. What can cause this problem?



package org.someorg.client.view.notifications;

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

import org.someorg.client.model.SessionData;
import org.someorg.client.model.notification.PendingNotificationModel;
import org.someorg.client.service.OrgServiceFactory;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Orientation;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.ListLoadResult;
import com.extjs.gxt.ui.client.data.Loader;
import com.extjs.gxt.ui.client.data.RpcProxy;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Text;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
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.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.RowData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class PendingNotificationsPanel extends ContentPanel {

private DateTimeFormat fmt = DateTimeFormat
.getFormat("MM/dd/yyyy HH:mm:ss");

private DateTimeFormat fmtShort = DateTimeFormat.getFormat("MM/dd/yyyy");

private Text titleText = new Text("Pending Notifications");

private CheckBox showAll = new CheckBox();

private Button refreshButton = new Button("Refresh",
IconHelper.createPath("icons/refresh.png"));
private ToolBar topToolBar = new ToolBar();
private ToolBar filterToolBar = new ToolBar();
private ContentPanel notificationsGridPanel = new ContentPanel();
private ContentPanel gridPanel = new ContentPanel();
private PendingNotificationBriefDetailsPanel notificationDetailsPanel = new PendingNotificationBriefDetailsPanel();
private ContentPanel actionButtonsPanel = new ContentPanel();
private Button goToAlertCaseButton = new Button("View");
private Button addButton = new Button("Add");
private Button modifyButton = new Button("Modify");
private Button deactivateButton = new Button("Deactivate");

private BaseListLoader<ListLoadResult<PendingNotificationModel>> gridLoader;
private RpcProxy<List<PendingNotificationModel>> proxy;
private Grid<PendingNotificationModel> grid;

public PendingNotificationsPanel() {
buildUI();
}

private void buildUI() {
Listener<BaseEvent> reloadGridListener = new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
gridLoader.load();
}
};

setHeaderVisible(false);
setScrollMode(Scroll.AUTO);

titleText.setStyleAttribute("padding-right", "10px");
titleText.setStyleAttribute("font-size", "13px");

notificationsGridPanel.setHeaderVisible(false);
notificationsGridPanel.setBorders(false);
notificationsGridPanel.setBodyBorder(false);

gridPanel.setHeaderVisible(false);
gridPanel.setBodyBorder(false);
gridPanel.setBorders(false);

showAll.setBoxLabel("Show All");
showAll.addListener(Events.Change, reloadGridListener);

actionButtonsPanel.setHeaderVisible(false);
actionButtonsPanel.setBorders(false);
actionButtonsPanel.setBodyBorder(false);
actionButtonsPanel.setFrame(false);

refreshButton
.addSelectionListener(new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
gridLoader.load();
}
});

proxy = new RpcProxy<List<PendingNotificationModel>>() {

@Override
protected void load(
Object loadConfig,
final AsyncCallback<List<PendingNotificationModel>> proxyCallback) {
grid.mask("Loading ...");
AsyncCallback<List<PendingNotificationModel>> callback = new AsyncCallback<List<PendingNotificationModel>>() {

@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
proxyCallback.onFailure(caught);
grid.unmask();
}

@Override
public void onSuccess(List<PendingNotificationModel> result) {
titleText.setText("Pending Notifications ("
+ result.size() + ")");
proxyCallback.onSuccess(result);
grid.unmask();
}
};
OrgServiceFactory.getNotificationService()
.getPendingNotificationsByUser(
SessionData.getCurrentUser(), showAll.getValue(), callback);
}
};

addListener(Events.Render, reloadGridListener);

setLayout(new BorderLayout());
setLayoutOnChange(true);

topToolBar.add(titleText);
topToolBar.add(refreshButton);

filterToolBar.add(showAll);

notificationsGridPanel.setTopComponent(topToolBar);

notificationsGridPanel.setLayout(new BorderLayout());

gridPanel.setLayout(new BorderLayout());
gridPanel.setTopComponent(filterToolBar);
gridPanel.add(getNotificationsGrid(), new BorderLayoutData(
LayoutRegion.CENTER));

actionButtonsPanel.setLayout(new RowLayout(Orientation.VERTICAL));
actionButtonsPanel.add(goToAlertCaseButton, new RowData(1, -1,
new Margins(4)));
actionButtonsPanel.add(addButton, new RowData(1, -1, new Margins(4)));
actionButtonsPanel.add(modifyButton, new RowData(1, -1, new Margins(4)));
actionButtonsPanel.add(deactivateButton, new RowData(1, -1, new Margins(4)));
gridPanel.add(actionButtonsPanel, new BorderLayoutData(
LayoutRegion.EAST, 125));

notificationsGridPanel.add(gridPanel, new BorderLayoutData(
LayoutRegion.CENTER));

add(notificationsGridPanel, new BorderLayoutData(LayoutRegion.CENTER,
70));

BorderLayoutData data = new BorderLayoutData(LayoutRegion.SOUTH, 350);
data.setCollapsible(true);
data.setSplit(true);
add(notificationDetailsPanel, data);
}

private Grid<PendingNotificationModel> getNotificationsGrid() {

gridLoader = new BaseListLoader<ListLoadResult<PendingNotificationModel>>(
proxy);

List<ColumnConfig> col = new ArrayList<ColumnConfig>();

col.add(new ColumnConfig(PendingNotificationModel.NOTIFICATION_TYPE,
"Notification Type", 100));
col.add(new ColumnConfig(PendingNotificationModel.DUE_DATE,
"Due Date", 120) {
{
setDateTimeFormat(fmtShort);
}
});
col.add(new ColumnConfig(PendingNotificationModel.SUBJECT, "Subject",
100));
col.add(new ColumnConfig(PendingNotificationModel.STATUS, "Status", 80));
col.add(new ColumnConfig(PendingNotificationModel.TARGET_USER,
"Target User", 80));
col.add(new ColumnConfig(PendingNotificationModel.ALERT_CASE_NUMBER,
"Alert / Case Number", 100));
col.add(new ColumnConfig(PendingNotificationModel.ALERT_CASE_NUMBER,
"E-Mail", 100));
col.add(new ColumnConfig(PendingNotificationModel.CREATE_DATE,
"Create Date", 120) {
{
setDateTimeFormat(fmt);
}
});

ColumnModel cm = new ColumnModel(col);

ListStore<PendingNotificationModel> store = new ListStore<PendingNotificationModel>(
gridLoader);

grid = new Grid<PendingNotificationModel>(store, cm);

gridLoader.addListener(Loader.Load, new Listener<BaseEvent>() {
public void handleEvent(BaseEvent be) {
new Timer() {
@Override
public void run() {
grid.getSelectionModel().select(0, false);
}
}.schedule(2);
}
});

grid.getSelectionModel().addSelectionChangedListener(
new SelectionChangedListener<PendingNotificationModel>() {
@Override
public void selectionChanged(
SelectionChangedEvent<PendingNotificationModel> se) {
notificationDetailsPanel.update(se.getSelectedItem());
}
});

return grid;
}
}

sven
8 Sep 2011, 11:52 AM
It would be much easier to help you if you could try to reproduce your problem in a small, standalone example that everybody can simple run. This means the example should implement EntryPoint and contain all dependencies

zeroed
21 Nov 2011, 9:25 PM
The problem was here:

notificationDetailsPanel.update(se.getSelectedItem())

This method was called every time when selected event occured.

And when grid was refreshed it called this method with a null. As a result - grid crush.

I added just a simple if .. != null and now everything if fine.