PDA

View Full Version : [FNR] RowEditor.dofocus() Throws NPE When Selecting CheckBox COlumn In Editable Grid



ccocco_dw
30 Mar 2011, 12:01 PM
When a cell is selected in an editable grid with a RowEditor, it puts the entire row into edit mode. If one of the columns is a CheckBoxSelectionModel, selecting a checkbox in that column puts the row in edit mode but throws a NullPointerException in RowEditor.doFocus() as getTargetColumnIndex() returns a -1 for the column index and this causes the subsequent code to fail. I'm providing the fix here:



public class GridRowEditor<M extends ModelData>
extends RowEditor<M>
{
@Override
protected void doFocus( Point pt )
{
if ( isVisible() )
{
int index = 0;

if ( pt != null )
{
index = getTargetColumnIndex( pt );
}

// The following is a kludge to fix an issue in the GXT RowEditor. Occassionally getTargetColumnIndex()
// returns -1 and this causes a NullPointerException for the cm.getColumn() call below since there isn't
// a valid column at that index...
if ( index == -1 )
{
index = 0;
}

ColumnModel cm = this.grid.getColumnModel();

for ( int i = index, len = cm.getColumnCount(); i < len; i++ )
{
ColumnConfig c = cm.getColumn( i );

if ( !c.isHidden() && c.getEditor() != null )
{
c.getEditor().getField().focus();
break;
}
}
}
}
}

Serge Adda
31 Mar 2011, 2:55 AM
The function RowEditor :: doFocus() doesn't work well if the grid has hidden columns.

The reason is that the getTargetColumnIndex (Point p) returns wrong index (clicked on column k, and index is k-1).

Here's the corrected code that fixes the bug, which doesn't increment index "i" when the column is hidden, because for it we don't have an associated header:


protected int getTargetColumnIndex(Point pt) {
int x = pt.x;
int match = -1;
for (int i = 0; i < grid.getColumnModel().getColumnCount(); ) {
ColumnConfig c = grid.getColumnModel().getColumn(i);
if (!c.isHidden()) {
if (El.fly(grid.getView().getHeaderCell(i)).getRegion().right >= x) {
match = i;
break;
}
i++;
}
}
return match;
}


Cheers!

sven
13 Sep 2011, 5:46 AM
This should probably be fixed in SVN now, can you revalidate?

Artistan
4 Oct 2011, 2:11 PM
similar problem in 4.0.6

ext-all-dev.js

editable row.

when using checkbox...
_root is null
Line 12554



Ext.define('app.view.ui.CallsEditGroups', {
extend: 'Ext.panel.Panel',

height: 800,
id: 'benadmin_calls_edit_groups',
layout: {
align: 'stretch',
type: 'vbox'
},
title: 'Groups',

initComponent: function() {
var me = this;
me.items = [
{
xtype: 'gridpanel',
itemId: 'grid',
store: 'BenAdminPhoneGroups',
flex: 1,
viewConfig: {
simpleSelect: true,
singleSelect: true
},
plugins: [
Ext.create('Ext.grid.plugin.RowEditing', {

})
],
columns: [
{
xtype: 'numbercolumn',
dataIndex: 'group_id',
text: 'Group_id',
format: 0
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'Name',
field: {
xtype: 'textfield',
name: 'name',
allowBlank: false
}
},
{
xtype: 'numbercolumn',
dataIndex: 'active_state',
text: 'Active',
format: 0,
field: {
xtype: 'checkboxfield',
name: 'active_state',
value: 1,
inputValue: 1,
uncheckedValue: 0
}
},
{
xtype: 'gridcolumn',
dataIndex: 'logo',
text: 'Logo',
field: {
xtype: 'textfield',
name: 'logo'
}
}
]
},
{
xtype: 'form',
itemId: 'form',
bodyPadding: 10,
title: 'Group Settings',
api: {
load: BenAdmin.DirectAPI.mod_Phone_Reports_Group.getInfo,
submit: BenAdmin.DirectAPI.mod_Phone_Reports_Group.setInfo
},
flex: 2,
items: [
{
xtype: 'fieldset',
title: 'My Fields',
items: [
{
xtype: 'hiddenfield',
name: 'group_id',
anchor: '100%'
},
{
xtype: 'textfield',
name: 'name',
fieldLabel: 'Name',
maxLength: 100,
anchor: '100%'
},
{
xtype: 'checkboxfield',
name: 'active',
fieldLabel: 'Active',
inputValue: 1,
uncheckedValue: 0,
anchor: '100%'
},
{
xtype: 'textfield',
name: 'logo',
fieldLabel: 'Logo',
anchor: '100%'
}
]
}
]
}
];
me.callParent(arguments);
}
});

micgala
5 Oct 2011, 3:44 AM
This is a gxt forum.
You probably post this in extjs instead...