Gwt TextInputCell不显示更改的值

时间:2012-08-20 13:44:27

标签: java gwt

我有一个带有TextInputCells列的CellTable。

当我通过UI设置值时,手动修改bean。 但是,当我将值直接设置到bean中时,我无法让Table显示修改。它将始终保持我手动分配的内容。

这是我的专栏:

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();
  }
};

以下是行动:

@UiHandler("myButton")
public void myButton_onClick(ClickEvent event) {
  for (MyBean my : listOfBeans)
    my.setValue("value");
}

我尝试在操作后致电table.redraw()或清除并重新填充ListDataProvider,但它不会改变任何内容。

我该怎么办?

由于

2 个答案:

答案 0 :(得分:2)

好的,我找到了一种(远程)方式。这很糟糕但是很有效。

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();
}

答案 1 :(得分:0)

即使我有同样的问题(我使用EditTextCell),但我无法找到解决方案。我几乎尝试了所有的事情。所以我提出了一个替代方案。

我将该列更改回TextCell并在SingleSelectionModel上添加了CellTable.setSelectionModel(SingleSelectionModel)。我创建了一个TextBox并将其放在CellTable下面。我使用它就像用户更改选择时一样,TextBox将使用该列的值进行更新。我添加了TextBox.addChangeHandler(),在此方法中我正在更新Bean,然后刷新DataProvider。 这种方法工作正常。希望能帮助到你。感谢..

相关问题