aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc
diff options
context:
space:
mode:
authorHenri Muurimaa <henri.muurimaa@gmail.com>2017-09-11 11:57:15 +0300
committerHenri Sara <henri.sara@gmail.com>2017-09-11 11:57:15 +0300
commitfb207248d5567a2661d5729d5149c7c8920a2efa (patch)
tree197085fb374e85ccc7eeb7d7998a7bcba9b09c43 /documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc
parente83f012cf5f1388dcab9be427575a655769f75e9 (diff)
downloadvaadin-framework-fb207248d5567a2661d5729d5149c7c8920a2efa.tar.gz
vaadin-framework-fb207248d5567a2661d5729d5149c7c8920a2efa.zip
Migrate wiki articles to Vaadin documentation (#9912)
* Vaadin Tutorial For Swing Developers * Setting And Reading Session Attributes * Enabling Server Push * Cleaning Up Resources In A UI * Sending Email From Java Applications * Using Parameters With Views * Optimizing Sluggish UI * Configuring Push For Your Enviroment * Setting And Reading Cookies * Using Polling * Creating An Application That Preserves State On Refresh * Finding The Current UI And Page And Vaadin Session * Sending Events From The Client To The Server Using RPC * Handling Logout * Remember To Set The Locale * Scalable Web Applications * MVC Basics In ITMill Toolkit * Access Control For Views * Customizing The Startup Page In An Application
Diffstat (limited to 'documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc')
-rw-r--r--documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc59
1 files changed, 59 insertions, 0 deletions
diff --git a/documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc b/documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc
new file mode 100644
index 0000000000..e10ce53c91
--- /dev/null
+++ b/documentation/articles/FindingTheCurrentUIAndPageAndVaadinSession.asciidoc
@@ -0,0 +1,59 @@
+[[finding-the-current-ui-and-page-and-vaadin-session]]
+Finding the current UI and page and vaadin session
+--------------------------------------------------
+There are many cases where you need a reference to the active `UI`, `Page`
+or `VaadinServiceSession`, for instance for showing notifications in a
+click listener. It is possible to get a reference to the component from
+the event and then a reference from the component to the UI but Vaadin
+also offers an easier way through two static methods:
+
+[source,java]
+....
+UI.getCurrent()
+Page.getCurrent()
+VaadinSession.getCurrent()
+....
+
+For example when you want to show the name of the current UI class:
+
+[source,java]
+....
+Button helloButton = new Button("Say Hello");
+ helloButton.addClickListener(new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Notification.show("This UI is "
+ + UI.getCurrent().getClass().getSimpleName());
+ }
+ });
+....
+
+Similarly for `VaadinServiceSession`, for instance to find out if the
+application is running in production mode:
+
+[source,java]
+....
+public void buttonClick(ClickEvent event) {
+ String msg = "Running in ";
+ msg += VaadinSession.getCurrent().getConfiguration()
+ .isProductionMode() ? "production" : "debug";
+ Notification.show(msg);
+}
+....
+
+And finally similiarly for `Page`. For instance adding a browser window
+resize listener can be added like this:
+
+[source,java]
+....
+javaPage.getCurrent().addBrowserWindowResizeListener(
+ new Page.BrowserWindowResizeListener() {
+ @Override
+ public void browserWindowResized(BrowserWindowResizeEvent event) {
+ Notification.show("Browser resized to " + event.getWidth() + "x" + event.getHeight());
+ }
+});
+....
+
+*Note* that these are based on `ThreadLocal` so they won't work in a
+background thread (or otherwise outside the standard request scope).