summaryrefslogtreecommitdiffstats
path: root/uitest/src
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2012-09-03 11:41:06 +0300
committerJohn Ahlroos <john@vaadin.com>2012-09-03 11:41:06 +0300
commit971b0684482dd3b7eb4efac09b9c24e1ea2b305d (patch)
tree6d6a4be640837500cfaa2f805a8602a9f4803871 /uitest/src
parent340cd7899812b444941584d383d930fe8155159b (diff)
parentf85c152a48686a8a0dca38ca12b4f3509cac056f (diff)
downloadvaadin-framework-971b0684482dd3b7eb4efac09b9c24e1ea2b305d.tar.gz
vaadin-framework-971b0684482dd3b7eb4efac09b9c24e1ea2b305d.zip
Merge branch 'master' into layoutgraph
Conflicts: shared/src/com/vaadin/shared/ComponentState.java
Diffstat (limited to 'uitest/src')
-rw-r--r--uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java4
-rw-r--r--uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java14
-rw-r--r--uitest/src/com/vaadin/tests/UpgradingSample.java197
-rw-r--r--uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html26
-rw-r--r--uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java45
-rw-r--r--uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java9
-rw-r--r--uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java7
-rw-r--r--uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java19
-rwxr-xr-xuitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java104
-rw-r--r--uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java13
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java47
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java4
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java5
-rw-r--r--uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java42
-rw-r--r--uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java5
15 files changed, 229 insertions, 312 deletions
diff --git a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
index e05979ede0..bceecaf35a 100644
--- a/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
+++ b/uitest/src/com/vaadin/launcher/ApplicationRunnerServlet.java
@@ -30,7 +30,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
import com.vaadin.server.AbstractApplicationServlet;
import com.vaadin.server.AbstractUIProvider;
import com.vaadin.server.WrappedHttpServletRequest;
@@ -116,8 +115,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet {
@Override
public Class<? extends UI> getUIClass(
- Application application, WrappedRequest request)
- throws UIRequiresMoreInformationException {
+ Application application, WrappedRequest request) {
return (Class<? extends UI>) classToRun;
}
});
diff --git a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
index 6162820dac..f45aac8173 100644
--- a/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
+++ b/uitest/src/com/vaadin/launcher/DevelopmentServerLauncher.java
@@ -54,6 +54,8 @@ public class DevelopmentServerLauncher {
public static void main(String[] args) {
System.setProperty("java.awt.headless", "true");
+ assertAssertionsEnabled();
+
// Pass-through of arguments for Jetty
final Map<String, String> serverArgs = parseArguments(args);
@@ -88,6 +90,18 @@ public class DevelopmentServerLauncher {
}
}
+ private static void assertAssertionsEnabled() {
+ try {
+ assert false;
+
+ throw new RuntimeException("You should run "
+ + DevelopmentServerLauncher.class.getSimpleName()
+ + " with assertions enabled. Add -ea as a VM argument.");
+ } catch (AssertionError e) {
+ // All is fine
+ }
+ }
+
/**
* Run the server with specified arguments.
*
diff --git a/uitest/src/com/vaadin/tests/UpgradingSample.java b/uitest/src/com/vaadin/tests/UpgradingSample.java
deleted file mode 100644
index 48e2222d7e..0000000000
--- a/uitest/src/com/vaadin/tests/UpgradingSample.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright 2011 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.tests;
-
-//
-// Millstone imports were replaced
-//
-// import org.millstone.base.Application;
-// import org.millstone.base.ui.*;
-// import org.millstone.base.data.*;
-//
-import com.vaadin.Application;
-import com.vaadin.data.Property;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Button.ClickEvent;
-import com.vaadin.ui.CustomComponent;
-import com.vaadin.ui.GridLayout;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.Panel;
-import com.vaadin.ui.UI.LegacyWindow;
-import com.vaadin.ui.TextField;
-import com.vaadin.ui.Tree;
-import com.vaadin.ui.VerticalLayout;
-
-/**
- * <p>
- * Example application demonstrating simple user login. This example is from
- * MillStone 3.1.1 examples section. Upgrading from 3.1.1 to 4.0.0 was done by
- * updating imports, also setTheme("corporate") call was added to application
- * init method.
- * </p>
- *
- * @since 3.1.1
- * @author Vaadin Ltd.
- */
-public class UpgradingSample extends Application.LegacyApplication implements
- Property.ValueChangeListener {
-
- /* Menu for navigating inside the application. */
- private final Tree menu = new Tree();
-
- /* Contents of the website */
- private final String[][] pages = {
- { "Welcome", "Welcome to our website..." },
- { "Products", "Public product information." },
- { "Contact", "Public contact information." },
- { "CRM", "CRM Database requiring login." },
- { "Intranet", "Internal information database." } };
-
- /* Application layout */
- private final GridLayout layout = new GridLayout(2, 1);
-
- /* Initialize the application */
- @Override
- public void init() {
-
- // Create the main window of the application
- final LegacyWindow main = new LegacyWindow("Login example", layout);
- setMainWindow(main);
-
- // Add menu and loginbox to the application
- final VerticalLayout l = new VerticalLayout();
- layout.addComponent(l, 0, 0);
- l.addComponent(menu);
- l.addComponent(new LoginBox());
-
- // Setup menu
- menu.setStyleName("menu");
- menu.addListener(this);
- menu.setImmediate(true);
- addToMenu(new String[] { "Welcome", "Products", "Contact" });
- }
-
- // Overriding usetUser method is a simple way of updating application
- // privileges when the user is changed
- @Override
- public void setUser(Object user) {
- super.setUser(user);
- if (user != null) {
- addToMenu(new String[] { "CRM", "Intranet" });
- }
- }
-
- public void addToMenu(String[] items) {
- for (int i = 0; i < items.length; i++) {
- menu.addItem(items[i]);
- menu.setChildrenAllowed(items[i], false);
- }
- if (menu.getValue() == null) {
- menu.setValue(items[0]);
- }
- }
-
- // Handle menu selection and update visible page
- @Override
- public void valueChange(Property.ValueChangeEvent event) {
- layout.removeComponent(1, 0);
- final String title = (String) menu.getValue();
- for (int i = 0; i < pages.length; i++) {
- if (pages[i][0].equals(title)) {
- final Panel p = new Panel(pages[i][0]);
- p.addComponent(new Label(pages[i][1]));
- p.setStyleName("strong");
- layout.addComponent(p, 1, 0);
- }
- }
- }
-
- // Simple loginbox component for the application
- public class LoginBox extends CustomComponent implements
- Application.UserChangeListener {
-
- // The components this loginbox is composed of
- private final TextField loginName = new TextField("Name");
-
- private final Button loginButton = new Button("Enter",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- login();
- }
- });
-
- private final Panel loginPanel = new Panel("Login");
-
- private final Panel statusPanel = new Panel();
-
- private final Button logoutButton = new Button("Logout",
- new Button.ClickListener() {
- @Override
- public void buttonClick(ClickEvent event) {
- close();
- }
- });
-
- private final Label statusLabel = new Label();
-
- // Initialize login component
- public LoginBox() {
-
- // Initialize the component
- loginPanel.addComponent(loginName);
- loginPanel.addComponent(loginButton);
- loginPanel.setStyleName("strong");
- loginName.setColumns(8);
- statusPanel.addComponent(statusLabel);
- statusPanel.addComponent(logoutButton);
-
- // Set the status of the loginbox and show correct
- // components
- updateStatus();
-
- // Listen application user change events
- UpgradingSample.this.addListener(this);
- }
-
- // Login into application
- public void login() {
- final String name = loginName.getValue();
- if (name != null && name.length() > 0) {
- setUser(name);
- }
- loginName.setValue("");
- }
-
- // Update login status on application user change events
- @Override
- public void applicationUserChanged(Application.UserChangeEvent event) {
- updateStatus();
- }
-
- // Update login status of the component by exposing correct
- // components
- private void updateStatus() {
- statusLabel.setValue("User: " + getUser());
- if (getUser() != null) {
- setCompositionRoot(statusPanel);
- } else {
- setCompositionRoot(loginPanel);
- }
- }
- }
-}
diff --git a/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html
new file mode 100644
index 0000000000..40ac075d53
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.html
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.VerifyAssertionsEnabled?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestsVerifyAssertionsEnabled::/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>Assertions are enabled</td>
+</tr>
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java
new file mode 100644
index 0000000000..d812ea644a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/VerifyAssertionsEnabled.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2011 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.tests;
+
+import com.vaadin.server.WrappedRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Label;
+
+public class VerifyAssertionsEnabled extends AbstractTestUI {
+
+ @Override
+ protected void setup(WrappedRequest request) {
+ try {
+ assert false;
+ addComponent(new Label("Assertions are not enabled"));
+ } catch (AssertionError e) {
+ addComponent(new Label("Assertions are enabled"));
+ }
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Tests whether the testing server is run with assertions enabled.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(9450);
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java b/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java
index d7e9155ded..1278032f3c 100644
--- a/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java
+++ b/uitest/src/com/vaadin/tests/application/ErrorInUnloadEvent.java
@@ -10,17 +10,18 @@ import com.vaadin.ui.FormLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.PasswordField;
-import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
public class ErrorInUnloadEvent extends AbstractTestCase {
private LegacyWindow mainWindow;
+ private Object user = null;
@Override
public void init() {
- if (getUser() == null) {
+ if (user == null) {
showLoginWindow();
} else {
showMainWindow();
@@ -55,7 +56,7 @@ public class ErrorInUnloadEvent extends AbstractTestCase {
String username = userField.getValue();
String password = passwordField.getValue();
- setUser(username);
+ user = username;
showMainWindow();
}
});
@@ -84,7 +85,7 @@ public class ErrorInUnloadEvent extends AbstractTestCase {
logout.addListener(new ClickListener() {
@Override
public void buttonClick(final ClickEvent event) {
- setUser(null);
+ user = null;
showLoginWindow();
}
diff --git a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
index 3013659ed7..8962f5de9a 100644
--- a/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
+++ b/uitest/src/com/vaadin/tests/application/RefreshStatePreserve.java
@@ -1,7 +1,7 @@
package com.vaadin.tests.application;
import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
+import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.server.AbstractUIProvider;
import com.vaadin.server.WrappedRequest;
import com.vaadin.tests.components.AbstractTestApplication;
@@ -9,6 +9,7 @@ import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
public class RefreshStatePreserve extends AbstractTestApplication {
+ @PreserveOnRefresh
public static class RefreshStateUI extends UI {
@Override
public void init(WrappedRequest request) {
@@ -22,12 +23,10 @@ public class RefreshStatePreserve extends AbstractTestApplication {
@Override
public void init() {
super.init();
- setUiPreserved(true);
addUIProvider(new AbstractUIProvider() {
@Override
public Class<? extends UI> getUIClass(Application application,
- WrappedRequest request)
- throws UIRequiresMoreInformationException {
+ WrappedRequest request) {
return RefreshStateUI.class;
}
});
diff --git a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
index 0e7dd1b242..89cbf5d3ff 100644
--- a/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
+++ b/uitest/src/com/vaadin/tests/application/ThreadLocalInstances.java
@@ -1,9 +1,9 @@
package com.vaadin.tests.application;
import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
import com.vaadin.server.DownloadStream;
import com.vaadin.server.PaintException;
+import com.vaadin.server.UIProvider;
import com.vaadin.server.WrappedRequest;
import com.vaadin.tests.components.AbstractTestApplication;
import com.vaadin.tests.integration.FlagSeResource;
@@ -73,12 +73,19 @@ public class ThreadLocalInstances extends AbstractTestApplication {
@Override
public void init() {
reportCurrentStatus("app init");
- }
+ addUIProvider(new UIProvider() {
+ @Override
+ public UI instantiateUI(Application application,
+ Class<? extends UI> type, WrappedRequest request) {
+ return mainWindow;
+ }
- @Override
- protected UI getUI(WrappedRequest request)
- throws UIRequiresMoreInformationException {
- return mainWindow;
+ @Override
+ public Class<? extends UI> getUIClass(Application application,
+ WrappedRequest request) {
+ return mainWindow.getClass();
+ }
+ });
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java
index b3ebb02751..58656cb7bf 100755
--- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java
+++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormUIInLoginHandler.java
@@ -1,52 +1,52 @@
-package com.vaadin.tests.components.loginform;
-
-import com.vaadin.tests.components.TestBase;
-import com.vaadin.ui.Label;
-import com.vaadin.ui.LoginForm;
-import com.vaadin.ui.LoginForm.LoginEvent;
-import com.vaadin.ui.LoginForm.LoginListener;
-import com.vaadin.ui.UI;
-
-public class LoginFormUIInLoginHandler extends TestBase {
-
- @Override
- protected void setup() {
- LoginForm lf = new LoginForm();
- lf.addListener(new LoginListener() {
-
- @Override
- public void onLogin(LoginEvent event) {
- UI r1 = UI.getCurrent();
- if (r1 != null) {
- addComponent(new Label("UI.getCurrent().data: "
- + r1.getData()));
- } else {
- addComponent(new Label("UI.getCurrent() is null"));
- }
- UI r2 = ((LoginForm) event.getSource()).getUI();
- if (r2 != null) {
- addComponent(new Label("event.getSource().data: "
- + r2.getData()));
- } else {
- addComponent(new Label(
- "event.getSource().getRoot() is null"));
- }
- }
- });
- addComponent(lf);
- getLayout().getUI().setData("This UI");
- }
-
- @Override
- protected String getDescription() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- protected Integer getTicketNumber() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
+package com.vaadin.tests.components.loginform;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.LoginForm;
+import com.vaadin.ui.LoginForm.LoginEvent;
+import com.vaadin.ui.LoginForm.LoginListener;
+import com.vaadin.ui.UI;
+
+public class LoginFormUIInLoginHandler extends TestBase {
+
+ @Override
+ protected void setup() {
+ LoginForm lf = new LoginForm();
+ lf.addListener(new LoginListener() {
+
+ @Override
+ public void onLogin(LoginEvent event) {
+ UI r1 = UI.getCurrent();
+ if (r1 != null) {
+ addComponent(new Label("UI.getCurrent().data: "
+ + r1.getData()));
+ } else {
+ addComponent(new Label("UI.getCurrent() is null"));
+ }
+ UI r2 = ((LoginForm) event.getSource()).getUI();
+ if (r2 != null) {
+ addComponent(new Label("event.getSource().data: "
+ + r2.getData()));
+ } else {
+ addComponent(new Label(
+ "event.getSource().getRoot() is null"));
+ }
+ }
+ });
+ addComponent(lf);
+ getLayout().getUI().setData("This UI");
+ }
+
+ @Override
+ protected String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
index ac4c3c8ea3..84c14763ab 100644
--- a/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
+++ b/uitest/src/com/vaadin/tests/components/loginform/LoginFormWithMultipleWindows.java
@@ -1,6 +1,7 @@
package com.vaadin.tests.components.loginform;
import com.vaadin.Application;
+import com.vaadin.server.AbstractUIProvider;
import com.vaadin.server.WrappedRequest;
import com.vaadin.ui.LoginForm;
import com.vaadin.ui.LoginForm.LoginEvent;
@@ -12,11 +13,17 @@ import com.vaadin.ui.UI.LegacyWindow;
public class LoginFormWithMultipleWindows extends Application {
@Override
- protected UI getUI(WrappedRequest request) {
- return new LoginFormWindow();
+ public void init() {
+ addUIProvider(new AbstractUIProvider() {
+ @Override
+ public Class<? extends UI> getUIClass(Application application,
+ WrappedRequest request) {
+ return LoginFormWindow.class;
+ }
+ });
}
- public class LoginFormWindow extends LegacyWindow {
+ public static class LoginFormWindow extends LegacyWindow {
public LoginFormWindow() {
super();
diff --git a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
index 34bf8f6715..18267e90b6 100644
--- a/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
+++ b/uitest/src/com/vaadin/tests/components/ui/LazyInitUIs.java
@@ -1,10 +1,9 @@
package com.vaadin.tests.components.ui;
-import com.vaadin.UIRequiresMoreInformationException;
-import com.vaadin.annotations.EagerInit;
+import com.vaadin.Application;
import com.vaadin.server.ExternalResource;
+import com.vaadin.server.UIProvider;
import com.vaadin.server.WrappedRequest;
-import com.vaadin.server.WrappedRequest.BrowserDetails;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.AbstractTestApplication;
import com.vaadin.ui.Label;
@@ -13,7 +12,7 @@ import com.vaadin.ui.UI;
public class LazyInitUIs extends AbstractTestApplication {
- @EagerInit
+ // @EagerInit
private static class EagerInitUI extends UI {
@Override
public void init(WrappedRequest request) {
@@ -22,23 +21,33 @@ public class LazyInitUIs extends AbstractTestApplication {
}
@Override
- public UI getUI(WrappedRequest request)
- throws UIRequiresMoreInformationException {
+ public void init() {
+ addUIProvider(new UIProvider() {
+
+ @Override
+ public UI instantiateUI(Application application,
+ Class<? extends UI> type, WrappedRequest request) {
+ return getUI(request);
+ }
+
+ @Override
+ public Class<? extends UI> getUIClass(Application application,
+ WrappedRequest request) {
+ return getUI(request).getClass();
+ }
+ });
+ }
+
+ private UI getUI(WrappedRequest request) {
if (request.getParameter("lazyCreate") != null) {
// UI created on second request
- BrowserDetails browserDetails = request.getBrowserDetails();
- if (browserDetails == null
- || browserDetails.getUriFragment() == null) {
- throw new UIRequiresMoreInformationException();
- } else {
- UI uI = new UI() {
- @Override
- protected void init(WrappedRequest request) {
- addComponent(getRequestInfo("LazyCreateUI", request));
- }
- };
- return uI;
- }
+ UI uI = new UI() {
+ @Override
+ protected void init(WrappedRequest request) {
+ addComponent(getRequestInfo("LazyCreateUI", request));
+ }
+ };
+ return uI;
} else if (request.getParameter("eagerInit") != null) {
// UI inited on first request
return new EagerInitUI();
diff --git a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
index 022db1bf3e..fe2fe16d93 100644
--- a/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
+++ b/uitest/src/com/vaadin/tests/components/ui/UIsInMultipleTabs.java
@@ -1,7 +1,6 @@
package com.vaadin.tests.components.ui;
import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
import com.vaadin.server.AbstractUIProvider;
import com.vaadin.server.WrappedRequest;
import com.vaadin.tests.components.AbstractTestApplication;
@@ -26,8 +25,7 @@ public class UIsInMultipleTabs extends AbstractTestApplication {
addUIProvider(new AbstractUIProvider() {
@Override
public Class<? extends UI> getUIClass(Application application,
- WrappedRequest request)
- throws UIRequiresMoreInformationException {
+ WrappedRequest request) {
return TabUI.class;
}
});
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java
index a96b8957c6..cfb24c732f 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/CreatingPreserveState.java
@@ -16,9 +16,10 @@
package com.vaadin.tests.minitutorials.v7a1;
+import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.server.WrappedRequest;
-import com.vaadin.ui.UI;
import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
/**
* Mini tutorial code for
@@ -28,6 +29,7 @@ import com.vaadin.ui.TextField;
* @author Vaadin Ltd
* @since 7.0.0
*/
+@PreserveOnRefresh
public class CreatingPreserveState extends UI {
private static int windowCounter = 0;
@@ -36,7 +38,6 @@ public class CreatingPreserveState extends UI {
TextField tf = new TextField("Window #" + (++windowCounter));
tf.setImmediate(true);
getContent().addComponent(tf);
- getApplication().setUiPreserved(true);
}
}
diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
index ba3042c48e..54cf8a94e0 100644
--- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
+++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DifferentFeaturesForDifferentClients.java
@@ -17,10 +17,9 @@
package com.vaadin.tests.minitutorials.v7a1;
import com.vaadin.Application;
-import com.vaadin.UIRequiresMoreInformationException;
+import com.vaadin.server.UIProvider;
import com.vaadin.server.WebBrowser;
import com.vaadin.server.WrappedRequest;
-import com.vaadin.server.WrappedRequest.BrowserDetails;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
@@ -35,21 +34,32 @@ import com.vaadin.ui.UI;
public class DifferentFeaturesForDifferentClients extends Application {
@Override
- protected UI getUI(WrappedRequest request)
- throws UIRequiresMoreInformationException {
- BrowserDetails browserDetails = request.getBrowserDetails();
- // This is a limitation of 7.0.0.alpha1 that there is no better way to
- // check if WebBrowser has been fully initialized
- if (browserDetails.getUriFragment() == null) {
- throw new UIRequiresMoreInformationException();
- }
+ public void init() {
+ super.init();
+ addUIProvider(new UIProvider() {
+ @Override
+ public Class<? extends UI> getUIClass(Application application,
+ WrappedRequest request) {
+ // could also use browser version etc.
+ if (request.getHeader("user-agent").contains("mobile")) {
+ return TouchRoot.class;
+ } else {
+ return DefaultRoot.class;
+ }
+ }
- // could also use screen size, browser version etc.
- if (browserDetails.getWebBrowser().isTouchDevice()) {
- return new TouchRoot();
- } else {
- return new DefaultRoot();
- }
+ // Must override as default implementation isn't allowed to
+ // instantiate our non-public classes
+ @Override
+ public UI instantiateUI(Application application,
+ Class<? extends UI> type, WrappedRequest request) {
+ try {
+ return type.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
}
}
diff --git a/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java b/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java
index 9f3019b21c..1f50110330 100644
--- a/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java
+++ b/uitest/src/com/vaadin/tests/vaadincontext/TestAddonContextListener.java
@@ -42,9 +42,8 @@ public class TestAddonContextListener implements AddonContextListener {
}
private boolean shouldModify(BootstrapResponse response) {
- UI uI = response.getUI();
- boolean shouldModify = uI != null
- && uI.getClass() == BootstrapModifyUI.class;
+ Class<? extends UI> uiClass = response.getUiClass();
+ boolean shouldModify = uiClass == BootstrapModifyUI.class;
return shouldModify;
}