PDA

View Full Version : [FIXED] NPE in TableBinder.onSort



Orion-
9 Jun 2008, 1:09 AM
Hello,

I am using the XmlTable sample code, where I added some lines to add a basic store sorter. I then get a NPE, when I use the "Load XML" button a *second* time.

I am using the very latest Beta4, just downloaded. Code is below. The sorter assumes that all elements in the table are equal. This is just a simplification, allowing not to complicate the code.

Orion-

PS: I already posted similar code to another thread about 10 days ago, but as that thread was marked as closed before I posted this code, and as it didn't get any more attention, I created this new thread. I hope not to a mistake in doing so.




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

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.binder.TableBinder;
import com.extjs.gxt.ui.client.data.BaseListLoader;
import com.extjs.gxt.ui.client.data.HttpProxy;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.data.ModelType;
import com.extjs.gxt.ui.client.data.XmlReader;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.store.Store;
import com.extjs.gxt.ui.client.store.StoreSorter;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.extjs.gxt.ui.client.widget.table.Table;
import com.extjs.gxt.ui.client.widget.table.TableColumn;
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;


public class XmlTablePage extends LayoutContainer implements EntryPoint {
public void onModuleLoad() {
RootPanel.get().add(this);
}

@Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);

setLayout(new FlowLayout(10));

List<TableColumn> columns = new ArrayList<TableColumn>();
columns.add(new TableColumn("Sender", .2f));
columns.add(new TableColumn("Email", .4f));
columns.add(new TableColumn("Phone", .2f));
columns.add(new TableColumn("State", .1f));
columns.add(new TableColumn("Zip", "Zip Code", .1f));

// create the column model
TableColumnModel cm = new TableColumnModel(columns);
final Table table = new Table(cm);

// defines the xml structure
ModelType type = new ModelType();
type.root = "records";
type.recordName = "record";
type.addField("Sender", "Name");
type.addField("Email");
type.addField("Phone");
type.addField("State");
type.addField("Zip");

// use a http proxy to get the data
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, "data.xml");
HttpProxy proxy = new HttpProxy(builder);

// need a loader, proxy, and reader
XmlReader reader = new XmlReader(type);

final BaseListLoader loader = new BaseListLoader(proxy, reader);

// Lines modified compared to sample ---------------------
ListStore store = new ListStore(loader);
store.setDefaultSort("Sender", Style.SortDir.ASC);
store.setStoreSorter(new StoreSorter() {
@Override
public int compare(
Store store, ModelData i1, ModelData i2, String property) {
return 0;
}
});
new TableBinder(table, store);
// End of modified lines ----------------------

ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setIconStyle("icon-table");
panel.setHeading("XML Table Demo");
panel.setLayout(new FitLayout());
panel.add(table);
panel.setSize(575, 350);

// add buttons
Button load = new Button("Load XML");
load.addSelectionListener(new SelectionListener() {
@Override
public void componentSelected(ComponentEvent ce) {
loader.load();
}
});
panel.addButton(load);
add(panel);
}
}

darrellmeyer
9 Jun 2008, 10:37 AM
Fix is in SVN.