PDA

View Full Version : [FNR] RowEditor changes read only field after Cancel + another RowEditor problem



BayerBusiness
9 Sep 2010, 5:23 AM
Actually, I was trying to track another issue, but building the testcase I found this one:
- You have an EditorGrid with a read only column (no CellEditor) and an editable column (with CellEditor)
- You are using the RowEditor plugin

- Click on the first line to show the RowEditor
- Cancel editing
- Click on the second line

Surprisingly, the read only value of the first column in the first line gets changed to the value of the second line (and the red triangle is shown).

Testcase:

import java.util.ArrayList;

import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.CellEditor;
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.EditorGrid;
import com.extjs.gxt.ui.client.widget.grid.RowEditor;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class Testcase implements EntryPoint {

private EditorGrid<ModelData> grid = null;

public void onModuleLoad() {
ArrayList<ColumnConfig> columnConfigs = new ArrayList<ColumnConfig>();

ColumnConfig columnConfig = new ColumnConfig("noeditor", "No Editor", 100);
columnConfig.setSortable(false);
columnConfigs.add(columnConfig);

columnConfig = new ColumnConfig("editor", "Editor", 200);
columnConfig.setSortable(false);
columnConfig.setEditor(new CellEditor(new TextField<String>()));
columnConfigs.add(columnConfig);

ColumnModel columnModel = new ColumnModel(columnConfigs);

ListStore<ModelData> store = new ListStore<ModelData>();
grid = new EditorGrid<ModelData>(store, columnModel);

grid.addPlugin(new RowEditor<ModelData>());

ModelData model = null;

model = new BaseModelData();
model.set("noeditor", "Example11");
model.set("editor", "Example12");
store.add(model);

model = new BaseModelData();
model.set("noeditor", "Example21");
model.set("editor", "Example22");
store.add(model);

Button btnReset = new Button("Reset");
btnReset.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
grid.getStore().removeAll();

ModelData model = null;

model = new BaseModelData();
model.set("noeditor", "Example11");
model.set("editor", "Example12");
grid.getStore().add(model);

model = new BaseModelData();
model.set("noeditor", "Example21");
model.set("editor", "Example22");
grid.getStore().add(model);
}
});

ContentPanel panel = new ContentPanel();
panel.setLayout(new FitLayout());
panel.setHeading("Example");
panel.add(grid);
panel.addButton(btnReset);

Viewport viewport = new Viewport();
viewport.setLayout(new FitLayout());

viewport.add(panel);

RootPanel.get().add(viewport);
}
}

Actually, I was trying to track another issue: I have a grid which looks almost like to the one of the testcase (but more columns and using CellEditor(ComboBox). On the first grid load, the RowEditor works fine. After grid.getStore().removeAll and loading data again, the RowEditor crashes in startEditing at this line:

Object val = cm.getEditor(i).preProcessValue(record.get(dIndex));

I'm not able to track it exactly (the testcase contains a refresh button to test this - but it works [in the testcase...]).

Could it be, that the code is crashing, as there is no check, if there is any CellEditor?




Shouldn't startEditing contain the same check on "no field" or "LabelField" as stopEditing (code position may be wrong)?

Regards,
HerrB

sven
9 Sep 2010, 5:27 AM
Shouldn't startEditing contain the same check on "no field" or "LabelField" as stopEditing (code position may be wrong)?



No it should not, because than the fields wont be updated and that would be wrong (never showing any value).

I cannot reproduce your problem against GXT 2.2.0 final. Can you test that out or make sure you are really using GXT 2.2 final?

Also why do you use an EditorGrid together with the RowEditor?

BayerBusiness
9 Sep 2010, 5:53 AM
>No it should not, because than the fields wont be updated
Ok, then I will try to find the element that becomes null in my code for whatever reason ... ;-)

Testcase shows the behaviour with
- GXT 2.2.0 (download last week from Downloads)
- GWT 2.0.2
- IE6
- Updated resource folder
- Completely recompiled code

Note, that you have to click into the first (non-editable) cell to get into the edit mode, cancel and click in the first or second cell of the second column (not important).

Unfortunately, I can't post an image, sorry.

>Also why do you use an EditorGrid together with the RowEditor?
That is a good question, I thought, you'll need an EditorGrid to use the RowEditor plugin.

I will change this in my code, the behaviour of the TestCase remains... ;-)

Regards,
HerrB

sven
9 Sep 2010, 5:58 AM
I was able to reproduce it. The problem is that you are using an EditorGrid together with the RowEditor. The RowEditor adds editors for the non editable cells(LabelFields are added) and that interfer with the EditroGrid.

sven
9 Sep 2010, 6:08 AM
I am going to change RowEditor to work together with EditorGrid.

sven
9 Sep 2010, 8:52 AM
As this change was tested by BayerBusiness and it is working for him without any modifications, this will be part of GXT 2.2.1. I will reply here one more time when this was commited.

sven
9 Sep 2010, 9:02 AM
Fixed in SVN as of revision 2219