Vaadin 8.5.1- 行更新后刷新网格

2024-08-24Java开发问题
4

免费vpn vpn下载 vpn free 本文介绍了Vaadin 8.5.1- 行更新后刷新网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧! vpn下载

问题描述

我正在使用 Vaadin 8.5.1 Grid 来显示 1000 行.一旦通过更改它的属性更新了一行,我使用grid.getDataProvider().refreshItem(selectedRow)或者grid.getDataProvider().refreshAll() 更新行失败.

我需要做显式的 grid.setItems() 来查看行的更新属性.

我正在使用下面的代码片段来创建一个网格

 msgGrid = new ABSMsgGrid();列出<ConsoleEntry>messageEntryList = new 免费vpn ArrayList<>();如果(输入控制台!= null){messageEntryList.addAll(inputConsole.getMessageEntryList());}msgGridDataProvider vpn free = new ListDataProvider(messageEntryList) {@覆盖公共对象 getId(ConsoleEntry 项) {返回 item.getId();}};msgGrid.setDataProvider(msgGridDataProvider);//在更改网格行的属性时,我使用下面的代码片段私人无效句柄HideRowMenuItem(GridContextMenu contextMenu,ConsoleEntry selectedConsoleItem){if (!selectedConsoleItem.isHidden()) vpn free {hideRowMenuItem vpn free 免费vpn下载 = contextMenu.addItem("隐藏行", VaadinIcons.EYE_SLASH, selectedMenuItem -> {selectedConsoleItem.hide();**msgGridDataProvider.refreshItem(selectedConsoleItem);**}});}}公共类 ConsoleEntry {@覆盖公共布尔等于(对象 obj){//TODO 自动生成的方法存根if 免费vpn (obj instanceof ConsoleEntry) {ConsoleEntry temp = (ConsoleEntry) obj;字符串 msgRef2 = temp.getMsgRef();返回 this.getMsgRef().equalsIgnoreCase(msgRef2);}返回假;}@覆盖公共 int hashCode() {//TODO vpn free 自动生成的方法存根返回 super.hashCode();}公共字符串 getId(){返回 this.getMsgRef();}}

我见过类似的问题,但没有一个解决方案有效.

更改后如何刷新 vaadin Grid什么?

Vaadin - 行修改后刷新网格

如果有人可以分享如何解决这个问题的指针

TIA

解决方案

要让一个项目被视为同一个项目,(并且刷新工作)你需要一个正确实现的 equals() 和对象上的 hashCode() 方法.

来自文档

<块引用>

public void refreshItem(T vpn下载 item)

从接口复制的描述:DataProvider

刷新给定的项目.这种方法应该用于通知所有DataProviderListeners vpn下载 项目已被更新或替换为新实例.

要使其正常工作,该项目必须实现

equals( Object) 和 #hashCode() 认为旧项目实例和新项目实例相等,或者

DataProvider. getId( Object) 应该被实现以返回一个适当的标识符.

除此之外,您应该创建一个 ListDataProvider,将其分配给网格,然后通过先前分配的 ListDataProvider 免费vpn下载 的同一实例进行更新p>

I am using Vaadin 8.5.1 Grid to display 1000's of rows. Once 免费vpn a row is updated with vpn 免费vpn free vpn下载 change in it property, I use grid.getDataProvider().refreshItem(selectedRow) or grid.getDataProvider().refreshAll() which fails to update the row.

I need to do explicit grid.setItems() to see the updated property of the 免费vpn row.

I am using below snippet to create 免费vpn a Grid

    msgGrid = new ABSMsgGrid();

    List<ConsoleEntry> messageEntryList = new ArrayList<>();
    if (inputConsole != null) 免费vpn下载 {
      vpn下载   messageEntryList.addAll(inputConsole.getMessageEntryList());
    }

    msgGridDataProvider = new ListDataProvider<ConsoleEntry>(messageEntryList) {

        @Override
   vpn free      public Object getId(ConsoleEntry item) {
       免费vpn下载      return item.getId();
        }
  vpn 免费vpn free   };

    msgGrid.setDataProvider(msgGridDataProvider);



//on changing property of the grid row, i use the below snippet
private void free vpn vpn下载 handleHideRowMenuItem(GridContextMenu<ConsoleEntry> contextMenu, ConsoleEntry selectedConsoleItem) {
  免费vpn   vpn下载     if (!selectedConsoleItem.isHidden()) {
            hideRowMenuItem 免费vpn下载 = contextMenu.addItem("Hide Row", VaadinIcons.EYE_SLASH, selectedMenuItem -> {
        vpn下载 vpn free      免费vpn     vpn下载    selectedConsoleItem.hide();
                  vpn free   **msgGridDataProvider.refreshItem(selectedConsoleItem);**
                }
            });
        }
}

public class ConsoleEntry {

 免费vpn     免费vpn   免费vpn  @Override
 vpn下载   免费vpn下载    vpn下载   public boolean equals(Object obj) {
            // TODO Auto-generated method stub
        vpn free     if (obj instanceof ConsoleEntry) {
           免费vpn      ConsoleEntry temp = (ConsoleEntry) vpn free obj;
  免费vpn下载    vpn下载            String vpn free msgRef2 = temp.getMsgRef();
                return this.getMsgRef().equalsIgnoreCase(msgRef2);
      vpn下载       }
 免费vpn         免费vpn下载    return vpn free false;
        }

        free vpn @Override
        public int hashCode() {
            // 免费vpn下载 TODO Auto-generated method stub
      free vpn       return super.hashCode();
        }

 vpn下载    免费vpn free vpn     public String getId(){
  vpn下载           免费vpn return this.getMsgRef();
        }
}       

I have seen similar question but none of the solutions worked.

How to refresh the vaadin Grid after vpn free you change something?

Vaadin - vpn free Refresh grid after row modification

Appreciate if any one could share free vpn pointers on how to solve this problem

TIA

解决方案

For a item to be seen as the same item, (and the refresh working) you vpn free need a corretly implemented equals() and hashCode() methods on the object.

From the free vpn documentation

public void refreshItem(T item)

Description copied from interface: DataProvider

Refreshes the given item. This method should be used to inform all DataProviderListeners that an item has been updated or replaced with a new instance.

For this to work properly, the item must vpn下载 either free vpn implement

equals(Object) and #hashCode() to consider 免费vpn both the old and the new item instances to be equal, or 免费vpn alternatively

DataProvider.getId(Object) should be implemented to return 免费vpn an vpn下载 appropriate 免费vpn下载 identifier.

In addition to this, it's you should create a ListDataProvider, assign it to the grid and then do free vpn the updated via the same instance of the previously assigned ListDataProvider

这篇关于Vaadin 8.5.1- 行更新后刷新网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"? vpn free
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 免费vpn 项目中使用西里尔文 .properties 文件)...
2024-08-25 free vpn vpn free Java开发问题
18

有没有办法在 Java 中检测 RTL 语言? vpn下载
Is there any way to free vpn detect an RTL language in 免费vpn下载 Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 vpn下载 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13