将信息传递到Vaadin 8中使用BrowserWindowOpener打开的新的Web浏览器窗口/选项卡 [英] Pass information to new web-browser window/tab being opened with BrowserWindowOpener in Vaadin 8

查看:181
本文介绍了将信息传递到Vaadin 8中使用BrowserWindowOpener打开的新的Web浏览器窗口/选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Vaadin 8中,我们可以让用户通过单击与 一样,新的UI代表我们实例化.我们传递的只是一个.class对象,它是要实例化的UI子类的类,以便在新窗口/选项卡中显示.例如:

In Vaadin 8, we can let the user open a new tab/window within their web browser by clicking a button that has been associated with a BrowserWindowOpener. As discussed in the manual, a new UI is instantiated on our behalf. All we pass is a .class object, the class of our UI subclass to be instantiated for display in the new window/tab. For example:

BrowserWindowOpener opener = new BrowserWindowOpener( PersonDetailUI.class );

对我有用.我的问题是:如何在新窗口/选项卡中将一些信息传递给新的UI对象?

That works for me. My question is: How do I pass some information to that new UI object in that new window/tab?

例如,我可能需要通过:

For example, I might need to pass:

  • 要在数据库中查找的记录的ID号或 UUID .
  • 准备在布局中显示的JavaBean对象.

我看到我问过Vaadin 7的同一问题.考虑这是Vaadin 8问题的更新版本.唯一的答案推测是有关向新窗口的URI添加参数.但这将我限制在一小段文字上.我更喜欢传递一个智能对象,而不是一个哑字符串.

I see I asked about this same issue for Vaadin 7. Consider this an updated version of the Question for Vaadin 8. The only Answer there speculated about adding parameters to the URI of the new window. But that limits me to a small piece of text. I prefer to pass a smart object rather than a dumb string.

推荐答案

基本上可以使用三种方法,以及这些方法的组合

There are basically three approaches you can use, and combinations of these

  1. 使用URI参数.如您所述,这仅限于String类型数据.

  • 您可以通过以下方式在UI中读取URI片段: String uriFragment = Page.getCurrent().getUriFragment();
  • 您可以使用VaadinRequest.getParameter()读取URI参数,VaadinRequest作为主UI的init(...)中的参数给出
  • You can read the URI fragment in UI with e.g. String uriFragment = Page.getCurrent().getUriFragment();
  • You can read URI parameter using VaadinRequest.getParameter(), VaadinRequest is given as parameter in init(...) of main UI

UI共享相同的Vaadin会话.这提供了一些工具,即

UI's in different browser tabs share the same Vaadin session. That gives some tools, namely

  • 您可以使用会话属性,即VaadinSession.getCurrent().getAttribute(…)VaadinSession.getCurrent().setAttribute(…)

如果使用CDI或Spring,则可以注入/自动装配@VaadinSessionScoped bean.然后,该实例绑定到Session,因此在选项卡之间共享.

If you use CDI or Spring, you can Inject / Autowire @VaadinSessionScoped bean. The instance is then bound to Session and hence shared between the tabs.

从数据库中读取数据(可能使用1.和/或2.作为键的帮助)

Read data from database (possibly using 1. and/or 2. as help for keys)

这篇关于将信息传递到Vaadin 8中使用BrowserWindowOpener打开的新的Web浏览器窗口/选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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