Search code examples
javabuttoncalendarvaadinmessagebox

Vaadin Button action and MessageBox with 2 actions to do


I have created a remove Button who delete the data inside my database and in my calendar. But I want to use MessageBox to be sure this is not a wrong choice. But I can't add 2 actions in my MessageBox.WithYesButton(), So Have you any idea how I can do it ? Here my code :

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

Thank you for your help !


Solution

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

    Whats more, you dont have to declare new ClickListener. You can simply do that:

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