问题
I have a CellTable with a column of TextInputCells.
When i set the value through the UI, manually, the bean is modified. But, then, when i set the value directly into the bean, i can't make the Table to show the modification. It will always keep what i assigned manually.
Here's my column :
FieldUpdater<MyBean, String> myFu = new FieldUpdater<MyBean, String>() {
@Override
public void update(int index, MyBean object, String value) {
object.setValue(value);
}
};
Column<MyBean, String> myCol = new Column<MyBean, String>(new TextInputCell()) {
@Override
public String getValue(MyBean object) {
return object.getValue();
}
};
Here's the action :
@UiHandler("myButton")
public void myButton_onClick(ClickEvent event) {
for (MyBean my : listOfBeans)
my.setValue("value");
}
I tried to call table.redraw() or clearing and refilling the ListDataProvider, after the action, but it doesn't change anything.
What can i do ?
Thanks
回答1:
Ok, i found a (far fetched) way. It's crappy but it works.
int inputTextColumnPos; // position of your column
...
@UiHandler("myButton")
public void myButton_onClick(ClickEvent event) {
for (MyBean my : listOfBeans) {
my.setValue("value");
// get the cell you want to update
TextInputCell cell = (TextInputCell) table.getColumn(inputTextColumnPos).getCell();
// re-create the view data for the cell because the current one isn't updated
TextInputCell.ViewData viewData = new TextInputCell.ViewData("value");
// CRUSH the other one
cell.setViewData(my, viewData);
}
// because we're never too sure
table.redraw();
}
回答2:
Even I had the same problem (I was using EditTextCell), but I was unable to find the solution. I tried almost all things. So I came up with an alternative.
I changed that column back to TextCell and added SingleSelectionModel on the CellTable.setSelectionModel(SingleSelectionModel). I created one TextBox and placed it below my CellTable. I made it to work like whenever user is changing the selection the TextBox will be updated with that column's value. I added TextBox.addChangeHandler(), within this method I'm updating the Bean and then refreshing the DataProvider.
This approach is working fine. Hope it helps. Thanks..
来源:https://stackoverflow.com/questions/12038881/gwt-textinputcell-doesnt-show-changed-value