有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Vaadin无缓冲网格无法关闭

我的Vaadin应用程序有一个奇怪的问题。我有一个屏幕,有两个独立的无缓冲网格。 用户可以编辑这两个网格中的数据,然后单击“保存”按钮保存所做的更改。 我的问题是,当用户单击“保存”时,我想关闭编辑器。 我尝试了以下代码:

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

我不明白为什么这段代码不起作用,编辑器保持打开状态。我还尝试调用cancel方法,但没有成功。 我用的是瓦丁14。 我在这里发布这篇文章,并没有太多希望找到答案,这个问题似乎真的很精确。 但幸运的是,也许有人也经历过类似的问题? 也许还有另一种更容易出错的方法迫使我的编辑关闭

任何建议都会有很大的帮助,提前感谢您能想到的一切

编辑:多一点代码
这是网格:

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


这是保存功能

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

这是保存按钮:

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

    return saveButton;
}

编辑2:
我注意到,当我单击两个网格中的一个元素时,我希望编辑器为该特定元素打开,并希望关闭另一个网格(与修改无关的网格)上的编辑器
这很有效!我的网格表现得像我想要的
似乎我只是在修改了其中一个单元格并单击“保存”按钮后才失去了对编辑器的控制
调用isOpen函数后,closeEditors函数在两个网格上都返回false,因此网格似乎认为它的编辑器已关闭,但它仍在我的UI上打开

编辑3:我找到了一个解决方法
好的,我已经解决了我的问题,在我的网格上添加了一个close事件监听器,并在close事件被触发时调用resetGrids。此函数只需从UI中删除网格,获取要显示的数据,然后再次添加网格,两个编辑器都将关闭
我想它解决了我的问题,但我想知道发生了什么

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

共 (0) 个答案