【问题标题】:Vaadin 7 - retrieve Beanitem from Grid Editor CommitEventVaadin 7 - 从网格编辑器 CommitEvent 中检索 Beanitem
【发布时间】:2018-12-11 15:36:45
【问题描述】:

我(仍在)使用 Vaadin 7.6.4 并尝试编写自己的自定义 FieldGroup.CommitHandler

我正在尝试从 commitEvent 本身中检索当前添加的项目(网格行)。

在调试时,如果我在 Debug-Inspector 中使用以下 trainwreck:commitEvent.getFieldBinder().getItemDataSource(),我可以看到所有数据都在名为 itemId 的属性中可用,但它是私有的。 itemId 是我想要访问的确切 bean 实体。我只能通过以下 trainwreck 访问实体的单个字段:commitEvent.getFieldBinder().getField(propertyId).getValue()。然而,这很麻烦,并没有给我作为一个整体的实体(准确地说,不是从实体中检索信息,而是从网格的显示元素中检索信息)。

有没有一种方法可以访问当前编辑的实体(即已编辑网格行的数据源),而无需将整个网格声明为全局字段并调用grid.getSelected()-方法?

另外,post-commit 和 preCommit 之间在数据方面是否存在差异?

【问题讨论】:

    标签: grid editor vaadin


    【解决方案1】:

    由于您显然在使用 BeanItemContainer 根据您对itemId 的评论,您可以尝试以下操作:

    BeanItem item = (BeanItem) commitEvent.getFieldBinder().getItemDataSource();
    MyBean bean = (MyBean) item.getBean();
    

    getBean() 在这种情况下返回itemId

    【讨论】:

    • 不幸的是,在我的行 BeanItem item = (BeanItem) commitEvent.getFieldBinder().getItemDataSource(); 中调用了一个异常 - 似乎“Item”不能转换为“BeanItem”
    猜你喜欢
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多