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
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 :)