java - Vaadin 按钮操作和消息框需要执行 2 个操作

标签 java button calendar vaadin messagebox

我创建了一个删除按钮,用于删除数据库和日历中的数据。但我想使用 MessageBox 来确保这不是一个错误的选择。但我无法在 MessageBox.WithYesButton() 中添加 2 个操作,所以你知道我该怎么做吗? 这是我的代码:

remove.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                for (CalendaringItem calendaringItem : calendaringList.getCalendarings()) {
                    MessageBox.createQuestion().withMessage("Do you want to delete this event ?").withYesButton(()
                            -> calendaringItem.delete(calendaringItem, name.getValue())).withNoButton().open();
                    //calendar.removeEvent(e);
                }
                window.close();
            }
        });

感谢您的帮助!

最佳答案

 MessageBox.createQuestion()
           .withMessage("Do you want to delete this event ?")
           .withYesButton( () -> {
               calendaringItem.delete(calendaringItem, name.getValue());
               //action
               //action2 ...
           })
           .withNoButton().open();

此外,您不必声明新的 ClickListener。您可以简单地这样做:

remove.addClickListener(event -> {
    actionAfterButtonClick();
});

关于java - Vaadin 按钮操作和消息框需要执行 2 个操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46100417/

相关文章:

html - 如何制作一个传递参数的html按钮?

html - 如何使 <a> 在边框中可点击?

java - 从颜色选择器获取错误的颜色值

java - 如何使用 JCalendar 选择数组中的元素?

Java SFTP 传输库

java - 从数组列表打印

java - 在线程池中重用 Runnable 有意义吗?

java - 如何使用 'ADD'按钮重复添加JPanel?如何在ActionListener()中调用JPanel?

android - 按钮文本在android中自动更改为大写字母

java - 在 Java 中创建自定义周计数器?