PDA

View Full Version : [FIXED] Row Editor Bug when adding first record



markmacumber
12 Jul 2009, 4:49 PM
- GXT version: 2.0
- Host mode / web mode / both: BOTH
- Browser and version: Firefox 3.0.10
- Operating System: Ubuntu 8.04
- Sample code: see below

We have a simple grid with 2 columns, that contains no records, we copied most of the code from the example: http://extjs.com/examples-dev/explorer.html#roweditorgrid and we wired up a callback for the AfterEdit event that gets fired after the used clicks "Save".



Listener<RowEditorEvent> saveListener = new Listener<RowEditorEvent>() {
public void handleEvent(RowEditorEvent ree) {
Record r = ree.getRecord();
//do our thing with the record...
}
};


In the very first instance where we are adding a new record to the grid, we are getting a null pointer on the record from the RowEditorEvent, (i.e. ree.getRecord() returns null).
We tracked down where it happens and believe it to be a bug.

The issues comes down to the GridView class, insertRows method, line 1207:



protected void insertRows(ListStore<ModelData> store, int firstRow, int lastRow, boolean isUpdate) {
if (isUpdate && firstRow == 0 && lastRow == store.getCount() - 1) {
refresh(false);
return;
}
...
}


When you add the first record in the grid and click save, the refresh(false) method gets fired, but when you add any record after that, it does not. The refresh method eventually calls the onHide() method on the RowEditor class that sets the field variable: "record" to null, and hence our call to ree.getRecord() returns null and we have ourselves a null pointer exception.

I think that the logic behind the call to refresh(false) (see above) is a bug, can someone please confirm this as it requries an ugly workaround which requires us to constantly have data in our grid before we do anything.

Cheers,
Mark

sven
13 Jul 2009, 6:14 AM
Can you please post some samplecode so that we know exactly what you do?

The roweditor is to edit an existing row, not to add a new one.

markmacumber
13 Jul 2009, 2:37 PM
Can you please post some samplecode so that we know exactly what you do?

The roweditor is to edit an existing row, not to add a new one.

Hi Sven,

Yes im aware that the row editor is for editing, the issue is when I programmatically add a a row to the grid (exactly like you do on the sample I posted a link for) via a button on a toolbar, then switch to edit mode on that new record.

Firstly, we add a listener to the row editor, to fire custom code after the user clicks "Save" on the row editor:


Listener<RowEditorEvent> saveListener = new Listener<RowEditorEvent>() {
public void handleEvent(RowEditorEvent ree) {
Record r = ree.getRecord();
//do our thing with the record...
}
};

...

rowEditor.addListener(Events.AfterEdit, saveListener);

Then, when the grid is empty, and we add a first row in the grid via the button:



addQueryButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
BaseModel newRecord = new BaseModel();
newRecord.set("query", "");
newRecord.set("originalTotal", "");

rowEditor.stopEditing(false);
queryGrid.getListStore().insert(newRecord, 0);
rowEditor.startEditing(queryGrid.getListStore().indexOf(newRecord), true);
}
});
The grid, at this point, is in edit mode, and when the user (i.e. me) clicks the "Save" button on the row editor, the code:



Record r = ree.getRecord();


returns null (i.e. r is null)

Is this enough information to go on with?

sven
15 Jul 2009, 6:20 AM
Fixed in SVN.

markmacumber
15 Jul 2009, 2:31 PM
Thanks Sven, I really appreciate the speed of the fix, this might be a simple question, but whats the best way to get the latest build with the fix?

sven
16 Jul 2009, 12:04 AM
Thanks Sven, I really appreciate the speed of the fix, this might be a simple question, but whats the best way to get the latest build with the fix?

You can get a support subscription. This includes SVN access.

http://www.extjs.com/store/gxt/#support-table

markmacumber
16 Jul 2009, 3:05 AM
Are there currently plans for any patch releases?

The_Jackal
16 Jul 2009, 4:03 PM
I second that - is there any plan to have nightly / weekly trunk builds?

Alternatively is there a guide to building from trunk?

markmacumber
16 Jul 2009, 6:53 PM
The guide for building on the trunk can be found in the online docs:

http://extjs.com/helpcenter/index.jsp

type in SVN into the search box and click on the SVN setup article...