在Vaadin 7.0中,如何刷新支持表的JavaBean数据?更换容器?替换豆类?

Bas*_*que 5 vaadin

Vaadin 7.0中,当使用BeanContainerTable中显示JavaBean数据时,使用新数据刷新Table的正确方法是什么?

Cha*_*ony 9

该表通过监听器监视表的项的属性.如果通过表的Item实例更改项的属性,则会通知并更新表:例如

container.getItem(beanInstance).getItemProperty("propertyName").setValue("newValue");

但是,如果在项目实例之外更改了bean,则需要告诉表刷新.最简单的方法(使用库存BeanContainer)只需删除然后添加项目.

或者 - 我建议,最好 - 您可以创建一个BeanItemContainer的扩展,它会触发ItemSetChange事件,这将导致表刷新.

public class RefreshableBeanItemContainer<BEANTYPE> extends BeanItemContainer<BEANTYPE> {
  public RefreshableBeanItemContainer(Collection<? extends BEANTYPE> collection) throws IllegalArgumentException {
    super(collection);
  }

  public RefreshableBeanItemContainer(Class<? super BEANTYPE> type) throws IllegalArgumentException {
    super(type);
  }

  public RefreshableBeanItemContainer(Class<? super BEANTYPE> type, Collection<? extends BEANTYPE> collection) throws IllegalArgumentException {
    super(type, collection);
  }

  public void refreshItems(){
    fireItemSetChange();
  }
}
Run Code Online (Sandbox Code Playgroud)

  • @BasilBourque目前(v7.3.8),[#fireItemSetChange()](https://vaadin.com/api/com/vaadin/data/util/AbstractContainer.html#fireItemSetChange())方法*是*protected =>唯一要调用的是通过子类. (2认同)