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 );
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:
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
Use URI parameters. As you mentioned, this is limited to String
type data.
String uriFragment = Page.getCurrent().getUriFragment();
VaadinRequest.getParameter()
, VaadinRequest is given as parameter in init(...) of main UIUI's in different browser tabs share the same Vaadin session. That gives some tools, namely
You can use session attributes, i.e. VaadinSession.getCurrent().getAttribute(…)
and VaadinSession.getCurrent().setAttribute(…)
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.
Read data from database (possibly using 1. and/or 2. as help for keys)