如何在vaadin中使用消息框等待选项? [英] how can I wait for options with a messagebox in vaadin?

查看:96
本文介绍了如何在vaadin中使用消息框等待选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Vaadin和Web应用程序并不陌生.我在使用Vaadin附加Steinwedel从MessageBox获取选择的选项时遇到问题(简单的是或否).

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.

我需要等待客户端说是"或否",然后像在Java JOption中那样为该选项运行我的代码.我有一个MessageBox的类,该类返回该选项:

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

但是,即使我打开了MessageBox,我的代码也始终运行着.

But my code always runs through, even though I have my MessageBox opened.

推荐答案

与传统的桌面GUI框架(如Swing)不同,使用Vaadin,您主要在服务器端进行编程,并从客户端监听事件(浏览器与用户一起浏览)相互作用).因此,显示对话框不会阻塞服务器端代码,因为不会发送来自客户端的(HTTP)请求的答案.相反,您应该显示对话框并听取对话框按钮的单击事件.

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

该示例摘自附加说明.在这里,他们使用println处理了OK按钮.

The example is taken from the add-on description. Here they handled the OK-button click with a println.

这篇关于如何在vaadin中使用消息框等待选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆