Monday, August 26, 2013

Re: EditTextCell column fires update when clicked if using SiingleSelectionModel

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?

On Sunday, August 25, 2013 2:09:31 PM UTC-4, Danilo Reinert wrote:
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

Em domingo, 25 de agosto de 2013 13h25min33s UTC-3, Steve C escreveu:
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?)


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment