From: Leif Åstrand Date: Thu, 22 Dec 2011 09:23:20 +0000 (+0200) Subject: Change the default to a two request bootstrap X-Git-Tag: 7.0.0.alpha1~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d9f5e4c8054fa3d99f30640c9ac44eb8e850fe50;p=vaadin-framework.git Change the default to a two request bootstrap Add @EagerInit annotation to indicate that that no browser details are required, enabling a one request bootstrap. --- diff --git a/src/com/vaadin/Application.java b/src/com/vaadin/Application.java index 700f657937..bc2575a5fe 100644 --- a/src/com/vaadin/Application.java +++ b/src/com/vaadin/Application.java @@ -29,7 +29,7 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import com.vaadin.annotations.RootInitRequiresBrowserDetails; +import com.vaadin.annotations.EagerInit; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Widgetset; import com.vaadin.data.util.converter.Converter; @@ -2268,8 +2268,8 @@ public class Application implements Terminal.ErrorListener, Serializable { if (!initedRoots.contains(rootId)) { boolean initRequiresBrowserDetails = preserveRoot - || root.getClass().isAnnotationPresent( - RootInitRequiresBrowserDetails.class); + || !root.getClass() + .isAnnotationPresent(EagerInit.class); if (initRequiresBrowserDetails && browserDetails == null) { pendingRoots.put(rootId, new PendingRootRequest(request)); } else { diff --git a/src/com/vaadin/annotations/EagerInit.java b/src/com/vaadin/annotations/EagerInit.java new file mode 100644 index 0000000000..0e9fbdb314 --- /dev/null +++ b/src/com/vaadin/annotations/EagerInit.java @@ -0,0 +1,27 @@ +package com.vaadin.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.ui.Root; + +/** + * Indicates that the init method in a Root class can be called before full + * browser details ({@link WrappedRequest#getBrowserDetails()}) are available. + * This will make the UI appear more quickly, as ensuring the availability of + * this information typically requires an additional round trip to the client. + * + * @see Root#init(com.vaadin.terminal.WrappedRequest) + * @see WrappedRequest#getBrowserDetails() + * + * @since 7.0 + * + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface EagerInit { + // No values +} diff --git a/src/com/vaadin/annotations/RootInitRequiresBrowserDetails.java b/src/com/vaadin/annotations/RootInitRequiresBrowserDetails.java deleted file mode 100644 index bd04d2e430..0000000000 --- a/src/com/vaadin/annotations/RootInitRequiresBrowserDetails.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -@VaadinApache2LicenseForJavaFiles@ - */ - -package com.vaadin.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import com.vaadin.terminal.WrappedRequest; -import com.vaadin.ui.Root; - -/** - * Indicates that the init method in a Root class should not be called until - * full browser details ({@link WrappedRequest#getBrowserDetails()}) are - * available. Ensuring the availability of this information will typically - * requires an additional round trip to the client, which will cause the - * application startup to progress more slowly. - * - * @see Root#init(com.vaadin.terminal.WrappedRequest) - * @see WrappedRequest#getBrowserDetails() - * - * @since 7.0 - * - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -public @interface RootInitRequiresBrowserDetails { - // No methods -} diff --git a/src/com/vaadin/terminal/WrappedRequest.java b/src/com/vaadin/terminal/WrappedRequest.java index 235a0513c7..a27213d921 100644 --- a/src/com/vaadin/terminal/WrappedRequest.java +++ b/src/com/vaadin/terminal/WrappedRequest.java @@ -16,7 +16,7 @@ import javax.servlet.http.HttpServletRequest; import com.vaadin.Application; import com.vaadin.RootRequiresMoreInformationException; -import com.vaadin.annotations.RootInitRequiresBrowserDetails; +import com.vaadin.annotations.EagerInit; import com.vaadin.terminal.gwt.server.WebBrowser; import com.vaadin.ui.Root; @@ -209,8 +209,8 @@ public interface WrappedRequest extends Serializable { * This information is only guaranteed to be available in some special * cases, for instance when {@link Application#getRoot} is called again * after throwing {@link RootRequiresMoreInformationException} or in - * {@link Root#init(WrappedRequest)} if the Root class is annotated with - * {@link RootInitRequiresBrowserDetails} + * {@link Root#init(WrappedRequest)} for a Root class not annotated with + * {@link EagerInit} * * @return the browser details, or null if details are not * available diff --git a/src/com/vaadin/ui/Root.java b/src/com/vaadin/ui/Root.java index 1a67edebde..4998baf90f 100644 --- a/src/com/vaadin/ui/Root.java +++ b/src/com/vaadin/ui/Root.java @@ -18,7 +18,7 @@ import java.util.List; import java.util.Map; import com.vaadin.Application; -import com.vaadin.annotations.RootInitRequiresBrowserDetails; +import com.vaadin.annotations.EagerInit; import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; import com.vaadin.event.ActionManager; @@ -60,9 +60,10 @@ import com.vaadin.ui.Window.CloseListener; * {@link #setContent(ComponentContainer)}. *

*

- * If a {@link RootInitRequiresBrowserDetails} annotation is present on a class - * extending Root, the framework will ensure {@link BrowserDetails} - * are present in the {@link WrappedRequest} passed to the init method. + * If a {@link EagerInit} annotation is present on a class extending + * Root, the framework will use a faster initialization method + * which will not ensure that {@link BrowserDetails} are present in the + * {@link WrappedRequest} passed to the init method. *

* * @see #init(WrappedRequest) @@ -193,6 +194,15 @@ public abstract class Root extends AbstractComponentContainer implements * Helper class to emulate the main window from Vaadin 6 using roots. This * class should be used in the same way as Window used as a browser level * window in Vaadin 6 together with {@Application.LegacyApplication + * + * + * + * + * + * + * + * + * * } */ @Deprecated @@ -1092,9 +1102,10 @@ public abstract class Root extends AbstractComponentContainer implements *

* The {@link WrappedRequest} can be used to get information about the * request that caused this root to be created. By default, the - * {@link BrowserDetails} are note guaranteed to be available in the - * request. Availability of the browser details can be requested by adding - * the {@link RootInitRequiresBrowserDetails} annotation to the class. + * {@link BrowserDetails} will be available in the request. If the browser + * details are not required, loading the application in the browser can take + * some shortcuts giving a faster initial rendering. This can be indicated + * by adding the {@link EagerInit} annotation to the Root class. *

* * @param request diff --git a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java index 83d34e55af..36a793bd6d 100644 --- a/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java +++ b/tests/testbench/com/vaadin/tests/application/RefreshStatePreserve.java @@ -1,13 +1,11 @@ package com.vaadin.tests.application; -import com.vaadin.annotations.RootInitRequiresBrowserDetails; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestApplication; import com.vaadin.ui.Label; import com.vaadin.ui.Root; public class RefreshStatePreserve extends AbstractTestApplication { - @RootInitRequiresBrowserDetails public static class RefreshStateRoot extends Root { @Override public void init(WrappedRequest request) { diff --git a/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java b/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java index f40de92777..93bbc3995e 100644 --- a/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java +++ b/tests/testbench/com/vaadin/tests/components/root/LazyInitRoots.java @@ -1,7 +1,7 @@ package com.vaadin.tests.components.root; import com.vaadin.RootRequiresMoreInformationException; -import com.vaadin.annotations.RootInitRequiresBrowserDetails; +import com.vaadin.annotations.EagerInit; import com.vaadin.terminal.ExternalResource; import com.vaadin.terminal.WrappedRequest; import com.vaadin.terminal.WrappedRequest.BrowserDetails; @@ -12,14 +12,13 @@ import com.vaadin.ui.Root; public class LazyInitRoots extends AbstractTestApplication { - @RootInitRequiresBrowserDetails - private static class LazyInitRoot extends Root { + @EagerInit + private static class EagerInitRoot extends Root { @Override public void init(WrappedRequest request) { BrowserDetails browserDetails = request.getBrowserDetails(); getContent().addComponent( - new Label("Lazy init root: " - + browserDetails.getUriFragment())); + new Label("Lazy init root: " + browserDetails)); } } @@ -41,9 +40,9 @@ public class LazyInitRoots extends AbstractTestApplication { }; return root; } - } else if (request.getParameter("lazyInit") != null) { + } else if (request.getParameter("eagerInit") != null) { // Root inited on second request - return new LazyInitRoot(); + return new EagerInitRoot(); } else { // The standard root Root root = new Root() { @@ -55,9 +54,9 @@ public class LazyInitRoots extends AbstractTestApplication { lazyCreateLink.setTargetName("_blank"); addComponent(lazyCreateLink); - Link lazyInitLink = new Link("Open lazyInit root", + Link lazyInitLink = new Link("Open eagerInit root", new ExternalResource(getURL() - + "?lazyInit#lazyInit")); + + "?eagerInit#eagerInit")); lazyInitLink.setTargetName("_blank"); addComponent(lazyInitLink); } diff --git a/tests/testbench/com/vaadin/tests/components/root/UriFragmentTest.java b/tests/testbench/com/vaadin/tests/components/root/UriFragmentTest.java index 8d87804448..6078161996 100644 --- a/tests/testbench/com/vaadin/tests/components/root/UriFragmentTest.java +++ b/tests/testbench/com/vaadin/tests/components/root/UriFragmentTest.java @@ -1,13 +1,11 @@ package com.vaadin.tests.components.root; -import com.vaadin.annotations.RootInitRequiresBrowserDetails; import com.vaadin.terminal.WrappedRequest; import com.vaadin.tests.components.AbstractTestRoot; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; -@RootInitRequiresBrowserDetails public class UriFragmentTest extends AbstractTestRoot { private final Label fragmentLabel = new Label();