Gwt TextInputCell doesn't show changed value

两盒软妹~` 提交于 2019-12-24 05:31:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!