how can I wait for options with a messagebox in vaadin?

对着背影说爱祢 提交于 2019-12-11 06:18:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42774714/how-can-i-wait-for-options-with-a-messagebox-in-vaadin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!