2

When i want to edit a textinputcell, i generally need two clicks : the first click gives focus to the cell and then to the input.

I have a celltable with 20 columns, all textinputcell - excel style. And this problem makes it totally unusable.

Here's a code sample :

FieldUpdater<MyBean, String> fieldUpdater = new FieldUpdater<MyBean, String>() {
  @Override
  public void update(int index, MyBean object, String value) {
    object.setValue(value);
  }
};

Column<MyBean, String> column = new Column<MyBean, String>(new TextInputCell()) {
  @Override
  public String getValue(MyBean object) {
    return objet.getValue();
  }
};

column.setFieldUpdater(fieldUpdater);
table.addColumn(column, "Col");

Did you have to face the problem ? Is there a know solution ?

Thanks

Maxime ARNSTAMM
  • 5,274
  • 10
  • 53
  • 76
  • 2
    Reproduced at http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellSampler at least, within Chrome. Didn't find any bug report in GWT issue tracker. – Thomas Broyer Oct 01 '12 at 09:44
  • 2
    It's not quite that: When you click on the input for the first time (i.e. if no other input is currently selected), then it works with one click (at least Chrome/Linux). But when another textinputcell is currently selected, then *unselecting* it takes an extra click. This is also the case when trying to navigate between textinputcells using the tab key. All of this feels more like "you must take an action to commit the value change". Maybe this is by design? But I also have a use case, where I can't use CellTables because of this behaviour. – Chris Lercher Oct 02 '12 at 15:49
  • Here's more info: I rewrote the EditTextCell class with console logging. The click event on the cell does indeed cause it to go into edit mode. But, then the selection model changes the selection, and the resulting blur event causes the commit t run, basically saving the value it just opened with. That means that isEditing is again false, so when the render after the selection change runs, it shows the plain text again. – stevec Aug 08 '17 at 20:13

3 Answers3

2

Set the KeyboardSelectionPolicy of the CellTable to DISABLED (i.e. cellTable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);).

Works for me with GWT 2.5 on Firefox/Chrome.

See https://code.google.com/p/google-web-toolkit/issues/detail?id=7706 additional details.

J0e3gan
  • 8,740
  • 10
  • 53
  • 80
Kearnel
  • 21
  • 3
-1

Allright, here's what i did : I noticed the EditTextCell doesn't take two clicks to change focus

So i duplicated the class (everything's private :/) and i made the following change in the method render :

Before :

if (viewData != null) {
  String text = viewData.getText();
  if (viewData.isEditing()) {
    /*
     * Do not use the renderer in edit mode because the value of a text
     * input element is always treated as text. SafeHtml isn't valid in the
     * context of the value attribute.
     */
    sb.append(template.input(text));
  } else {
    // The user pressed enter, but view data still exists.
    sb.append(renderer.render(text));
  }
} else if (value != null) {
  sb.append(renderer.render(value));
}

After :

    if (viewData != null) {
        String text = viewData.getText();
        sb.append(template.input(text));
    }
    else if (value != null) {
        sb.append(template.input(value));
    }

I'm only using the template and never the renderer.

Bonus : Since you're using your own copy of the cell, you can edit the template. I added a width (constructor arg) :

interface Template extends SafeHtmlTemplates {
    @Template("<input type=\"text\" value=\"{0}\" style=\"width:{1}px\" tabindex=\"-1\"></input>")
    SafeHtml input(String value, String width);
}

And i call the template like this : sb.append(template.input(text, width));

Hope that helps :)

Maxime ARNSTAMM
  • 5,274
  • 10
  • 53
  • 76
  • Hi, can you help with http://stackoverflow.com/questions/18367891/gwt-edittextcell-to-look-exactly-like-textinputcell?noredirect=1#comment26970221_18367891. Did you modify the EditTextCell or InputTextCell? – Namita Aug 21 '13 at 21:49
  • I modified the EditTextCell because it's the one that worked :) – Maxime ARNSTAMM Aug 22 '13 at 08:41
-1

Check if the selectionModel of the grid has been set on the cell and not on the row. It might solve your problem.

davgut
  • 624
  • 6
  • 7