简体   繁体   English

Vaadin 无缓冲网格不会关闭

[英]Vaadin unbuffered grids won't close

I am having a weird problem on my Vaadin app.我的 Vaadin 应用程序遇到了一个奇怪的问题。 I have a screen with two separate unbuffered grids.我有一个带有两个独立无缓冲网格的屏幕。 The user is able to edit the data in those two grids and then click a "Save" button to save the changes made.用户可以编辑这两个网格中的数据,然后单击“保存”按钮保存所做的更改。 My problem is that I want to close the editors when the user clicks on "Save".我的问题是当用户单击“保存”时我想关闭编辑器。 I tried the following code:我尝试了以下代码:

private void closeEditors() {
    if (tab1.getEditor().isOpen()) {
        tab1.getEditor().closeEditor();
    }
    if (tab2.getEditor().isOpen()) {
        tab2.getEditor().closeEditor();
    }
} 

I don't understand why this code doesn't work, editors stay opened.我不明白为什么这段代码不起作用,编辑器保持打开状态。 I also tried calling the cancel method but in vain.我也尝试调用cancel方法,但徒劳无功。 I am using Vaadin 14. I am posting this here with not much hope of finding an answer, this problem seems really precise.我正在使用 Vaadin 14。我在这里发布这个并没有太大希望找到答案,这个问题似乎真的很精确。 But with any luck, maybe someone has experienced a similar issue?但是运气好的话,也许有人遇到过类似的问题? Maybe there is another glitchier way of forcing my editors to close?也许还有另一种更糟糕的方式迫使我的编辑关闭?

Any suggestion would be of great help, thanks in advance for anything you could think of !任何建议都会有很大帮助,提前感谢您能想到的任何事情!

EDIT: a little more code编辑:更多代码
This is the grids:这是网格:

private Grid<Map<String, String>> tab1;
private Grid<Map<String, List<String>>> tab2;


This is the save function这是保存 function

public void saveData() {
    saveDataFromTab1();
    saveDataFromTab2();

    try {
        ServicesProxyImpl.getInstance().updateInBD(someObject);
        saveButton.setEnabled(false);
        cancelButton.setEnabled(false);
        closeEditors();

        Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_OK);
        dialog.open();
    } catch (JAXBException e) {
        e.printStackTrace();
        Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_KO);
        dialog.open();
    }
}

And this is the save button:这是保存按钮:

public Button getSaveButton() {
    Button saveButton= VaadinComponentUtils.generateButton("Save",
            VaadinIcon.CHECK_CIRCLE_O, null, true);
    saveButton.setEnabled(false);
    saveButton.addClickListener(event -> saveData());

    return saveButton;
}

EDIT 2:编辑2:
I have noticed something, when I click on an element of one of my two grids, I want the editor to open for that specific element and I want to close the editor on the other grid (the one not concerned by the modification).我注意到了一些事情,当我单击两个网格之一的元素时,我希望编辑器为该特定元素打开,并且我想关闭另一个网格上的编辑器(与修改无关的那个)。
This works.这行得通。 My grids behave like I want.我的网格表现得如我所愿。
It seems I am only losing control over my editors after I have actually modified one of the cells and clicked on my save button.看来我只是在实际修改了一个单元格并单击了我的保存按钮后才失去对编辑器的控制。
The isOpen function returns false on both grids after I call my closeEditors function, so it seems the grid thinks its editor is closed but it is still opened on my UI.在我调用closeEditors function 后, isOpen function 在两个网格上都返回 false,所以网格似乎认为它的编辑器已关闭,但它仍然在我的 UI 上打开。

EDIT 3: I have found a workaround编辑 3:我找到了解决方法
Well, I have solved my problem by adding a close event listener on both my grids and calling resetGrids when the close event is fired.好吧,我通过在我的网格上添加一个关闭事件侦听器并在触发关闭事件时调用resetGrids解决了我的问题。 This function simply removes the grids from the UI, fetches the data to be displayed and then adds the grid one again, both editors being closed.此 function 只是从 UI 中删除网格,获取要显示的数据,然后再次添加网格,两个编辑器都被关闭。
I guess it solves my problem but I would have wanted to understand what was going on...我想它解决了我的问题,但我想了解发生了什么......

    private void closeEditors() {
        tableauHoraires.getEditor().addCloseListener(e -> resetGrids());
        tableauRamassagePorteAPorte.getEditor().addCloseListener(e -> resetGrids());
        if (tableauRamassagePorteAPorte.getEditor().isOpen()) {
            tableauRamassagePorteAPorte.getEditor().closeEditor();
        }
        if (tableauHoraires.getEditor().isOpen()) {
            tableauHoraires.getEditor().closeEditor();
            tableauHoraires.getEditor().refresh();
        }
    }

Make sure that the objects in your grid have proper equals and hashcode methods and that the field(s) being edited do not influence them.确保网格中的对象具有正确的 equals 和 hashcode 方法,并且正在编辑的字段不会影响它们。

I use the PK from the database.我使用数据库中的PK。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM