I'm little new to Vaadin and web applications. I'm having problems getting the selected option (a simple yes or no) from a MessageBox
with Vaadin add-on Steinwedel.
I need to wait for the client to say "yes" or "no", then run my code for that option, as in java JOption
. I have a class for MessageBox
that returns the option:
int option = MessageBox.showDialog (message, title, QUESTION_YES_NO_OPTION);
But my code always runs through, even though I have my MessageBox
opened.
Unlike in a traditional desktop GUI framework such as Swing, with Vaadin you are programming primarily on the server side and listen to events from the client side (browser with user interaction). So, showing a dialog does not block on the server side code because the answer to the (HTTP) request that came from client wouldn't be sent. Instead you should show the dialog and listen to the click events of the dialog buttons.
MessageBox
.createInfo()
.withCaption("Info")
.withMessage("Hello World!")
.withOkButton(() -> System.out.println("Ok pressed."))
.open();
The example is taken from the add-on description. Here they handled the OK-button click with a println.