在 Vaadin 7.0 中,如何刷新支持表的 JavaBean 数据?更换容器?换豆子? [英] In Vaadin 7.0, how to refresh JavaBean data backing a Table? Replace Container? Replace Beans?

查看:24
本文介绍了在 Vaadin 7.0 中,如何刷新支持表的 JavaBean 数据?更换容器?换豆子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vaadin 7.0 中,当显示 JavaBean 数据在 带有BeanContainer,什么是用新数据刷新表的正确方法是什么?

In Vaadin 7.0, when displaying JavaBean data in a Table with a BeanContainer, what is the proper way to refresh the Table with new data?

推荐答案

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

The table monitors the the Properties of the Items of the table via Listeners. If you change the property of an item via the Item instance of the table, the table will be notified and updated : e.g.

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

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

If, however, the bean is changed outside of the item instance, you need to tell the table to refresh. The easiest way (using the stock BeanContainer) is to simply remove then add the items.

或者——我建议最好——你可以创建一个 BeanItemContainer 的扩展来触发一个 ItemSetChange 事件,这将导致表格刷新.

Alternatively - and, I suggest, preferably - you could create an extension of BeanItemContainer that fires an ItemSetChange event, which will cause the table to refresh.

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

这篇关于在 Vaadin 7.0 中,如何刷新支持表的 JavaBean 数据?更换容器?换豆子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆