]> source.dussan.org Git - vaadin-framework.git/commitdiff
Made Root.getCurrent() work in LoginForm LoginListener (#9372)
authorArtur Signell <artur@vaadin.com>
Wed, 22 Aug 2012 18:18:01 +0000 (21:18 +0300)
committerArtur Signell <artur@vaadin.com>
Wed, 22 Aug 2012 18:18:25 +0000 (21:18 +0300)
server/src/com/vaadin/ui/LoginForm.java
tests/testbench/com/vaadin/tests/components/loginform/LoginFormRootInLoginHandler.java [new file with mode: 0755]

index c8634ea81a392fa53e931836df3547fd88c82ac8..bb7767084c3147ebc8e011592dd15a56441b792f 100644 (file)
@@ -99,6 +99,9 @@ public class LoginForm extends CustomComponent {
                 throws IOException {
             String requestPathInfo = request.getRequestPathInfo();
             if ("/loginHandler".equals(requestPathInfo)) {
+                // Ensure Root.getCurrent() works in listeners
+                Root.setCurrent(getRoot());
+
                 response.setCacheTime(-1);
                 response.setContentType("text/html; charset=utf-8");
                 response.getWriter()
diff --git a/tests/testbench/com/vaadin/tests/components/loginform/LoginFormRootInLoginHandler.java b/tests/testbench/com/vaadin/tests/components/loginform/LoginFormRootInLoginHandler.java
new file mode 100755 (executable)
index 0000000..2c0a874
--- /dev/null
@@ -0,0 +1,52 @@
+package com.vaadin.tests.components.loginform;\r
+\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.ui.Label;\r
+import com.vaadin.ui.LoginForm;\r
+import com.vaadin.ui.LoginForm.LoginEvent;\r
+import com.vaadin.ui.LoginForm.LoginListener;\r
+import com.vaadin.ui.Root;\r
+\r
+public class LoginFormRootInLoginHandler extends TestBase {\r
+\r
+    @Override\r
+    protected void setup() {\r
+        LoginForm lf = new LoginForm();\r
+        lf.addListener(new LoginListener() {\r
+\r
+            @Override\r
+            public void onLogin(LoginEvent event) {\r
+                Root r1 = Root.getCurrent();\r
+                if (r1 != null) {\r
+                    addComponent(new Label("Root.getCurrent().data: "\r
+                            + r1.getData()));\r
+                } else {\r
+                    addComponent(new Label("Root.getCurrent() is null"));\r
+                }\r
+                Root r2 = ((LoginForm) event.getSource()).getRoot();\r
+                if (r2 != null) {\r
+                    addComponent(new Label("event.getSource().data: "\r
+                            + r2.getData()));\r
+                } else {\r
+                    addComponent(new Label(\r
+                            "event.getSource().getRoot() is null"));\r
+                }\r
+            }\r
+        });\r
+        addComponent(lf);\r
+        getLayout().getRoot().setData("This root");\r
+    }\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        // TODO Auto-generated method stub\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        // TODO Auto-generated method stub\r
+        return null;\r
+    }\r
+\r
+}\r