EditTextCell column fires update when clicked if using SiingleSelectionModel

165 views
Skip to first unread message

Steve C

unread,
Aug 25, 2013, 12:25:33 PM8/25/13
to google-we...@googlegroups.com
In a simple celltable, if I set a SingleSelectionModel, then clicking on an EditTextCell triggers the updater for that column, even though the editor doesn't even open (and the value is the current value).  Without the selection model this doesn't happen.

Is this expected behavior?

I've pasted sample code below.

Also worth noting is the behavior if I hit Enter to clear the alert box - that triggers whatever enter would do on the cell (like open it for editing). Better yet, try editing a cell, and clicking on a different row, then using Enter to close all of the alerts that come up.

public class EditTextCellBug implements EntryPoint {
    public void onModuleLoad() {
       
        List<Bean> list = new ArrayList<Bean>();
        list.add(new Bean("John"));
        list.add(new Bean("Jane"));
       
        ListDataProvider<Bean> provider = new ListDataProvider<Bean>(list);
       
        // problem occurs whether we use explicit key provider or not
        CellTable<Bean> ct = new CellTable<Bean>(provider);
        provider.addDataDisplay(ct);
       
        Column<Bean, String> col = new Column<Bean, String>(new EditTextCell()) {
            @Override
            public String getValue(Bean b) {
                return b.name;
            }
        };
        col.setFieldUpdater(new FieldUpdater<Bean, String>() {
            @Override
            public void update(int index, Bean b, String value) {
                Window.alert(b.name + " updating to " + value);
                b.name = value;
            }
        });
        ct.addColumn(col);
       
        // problem doesn't occur if we don't set the selection model
        SingleSelectionModel<Bean> selModel = new SingleSelectionModel<Bean>();
        ct.setSelectionModel(selModel);
       
        RootPanel.get().add(ct);
       
        // doesn't fire updater - only manual selection does
        selModel.setSelected(list.get(0), true);
    }
}
class Bean {
    public String name;
    public Bean(String name) {
        this.name = name;
    }
}

As a side note, with the single selection model in place, it takes a second click to open the cell for editing if the row wasn't currently selected. (I think I may have a misunderstanding of the role of a selection model, since it doesn't seem to be needed for simple editing, and there are three states a row can have, no bg, yellow bg, and blue, using the default styling.  Do I only need one if I actually want to "do something" with the user's selection?)


Danilo Reinert

unread,
Aug 25, 2013, 2:09:31 PM8/25/13
to google-we...@googlegroups.com
I guess that's because the EditTextCell fires an update event even you haven't changed it's value. 

I was having a similar issue and made a simple patch to the EditTextCell component in order to avoid always firing the update event. Now my EditTextCell only fires when its value has really changed.

--
D. Reinert

Steve C

unread,
Aug 26, 2013, 10:47:43 AM8/26/13
to google-we...@googlegroups.com
I'vde been looking through the EditTextCell code, and can't figure out where that happens. In onBrowserEvent it looks like the flow of execution should end up in edit mode under the circumstances I described.

What patch did you make?

Danilo Reinert

unread,
Aug 27, 2013, 8:52:43 AM8/27/13
to google-we...@googlegroups.com
At L133, add this method:

        boolean isCurrentEqualsToOriginal() {
            return equalsOrBothNull(original, text);
        }

At L300, add this verification to the current one:

          if (valueUpdater != null && !viewData.isCurrentEqualsToOriginal()) {
            valueUpdater.update(value);
        }

Now, your EditTextCell will only fire an update event when the value has actually changed.

--
D. Reinert

Danilo Reinert

unread,
Aug 27, 2013, 9:15:52 AM8/27/13
to google-we...@googlegroups.com
Let me know if it worked for you. I was thinking about to submit this patch and would be interesting to validate that this is really an issue.

Additionally, I've also made a "EditSelectCell". It's a simple cell that, on the click, turns out to be a select element, and after chosen a value, it changes back to be a simple cell. It's a bit different from the existing SelectionCell that is always shown as a select.

--
D. Reinert

Steve C

unread,
Aug 30, 2013, 9:49:30 AM8/30/13
to google-we...@googlegroups.com
Danilo,

That worked for me, although the line numbers were slightly different.  I edited code from 2.5.1 - was yours based on an earlier version?

I'm still trying to figure out the logic flow, given that the issue doesn't occur until I add a selection model.

I like the selection cell concept.  I've made a radio group cell to handle a set of radio buttons, but the drawback has been that it takes up a lot of space.  Your concept layered on top of that might be a good solution, especially if I can use a popup when the buttons are displayed. (General thought - it seems like a generic popup cell might be useful, which things like DatePickerCell could extend, but that would also give inherited logic for any other sort of custom popup cell I'd want to create.)

Danilo Reinert

unread,
Aug 30, 2013, 11:22:32 AM8/30/13
to google-we...@googlegroups.com
Glad to hear that your problem is solved.
I'm going to open an issue about this problem.
It might be useful for others as it was for us.

About why does it happens when SelectionModel is set, I guess that the SelectionModel forces an update on the click. So it just anticipates this unexpected behavior. If you don't use SelectionModel you still realize that EditTextCell fires update when you click on the cell for editing, and click out with no changes (that was my exactly problem).

The abstract popup cell concept seems to be very extendable. It would be interesting to have such a feature.

Eventually, if the EditSelectCell component will be useful for you, you can email me and I'll share it with you.

--
D. Reinert

linus...@gmail.com

unread,
Jan 4, 2021, 2:14:14 PM1/4/21
to GWT Users
Hi D. Reinert.

I know this is a very old thread, but I could actually use your EditSelectCell.  Do you possibly still have the code available?

Reply all
Reply to author
Forward
0 new messages