blob: 57fc9f3e6261263cc604304f39a2c6466086ed71 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
package com.vaadin.tests.components.ui;
import com.vaadin.server.ExternalResource;
import com.vaadin.server.Page;
import com.vaadin.server.UIClassSelectionEvent;
import com.vaadin.server.UICreateEvent;
import com.vaadin.server.UIProviderEvent;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.tests.components.AbstractTestUIProvider;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
public class LazyInitUIs extends AbstractTestUIProvider {
// @EagerInit
private static class EagerInitUI extends UI {
@Override
public void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
layout.addComponent(getRequestInfo("EagerInitUI", request));
}
}
@Override
public UI createInstance(UICreateEvent event) {
return getUI(event);
}
@Override
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
return getUI(event).getClass();
}
private UI getUI(UIProviderEvent event) {
VaadinRequest request = event.getRequest();
if (request.getParameter("lazyCreate") != null) {
// UI created on second request
UI uI = new UI() {
@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
layout.addComponent(getRequestInfo("LazyCreateUI", request));
}
};
return uI;
} else if (request.getParameter("eagerInit") != null) {
// UI inited on first request
return new EagerInitUI();
} else {
// The standard UI
UI uI = new UI() {
@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
layout.addComponent(getRequestInfo("NormalUI", request));
String location = getPage().getLocation().toString();
Link lazyCreateLink = new Link("Open lazyCreate UI",
new ExternalResource(location.replaceFirst(
"(\\?|#|$).*", "?lazyCreate#lazyCreate")));
lazyCreateLink.setTargetName("_blank");
layout.addComponent(lazyCreateLink);
Link lazyInitLink = new Link("Open eagerInit UI",
new ExternalResource(location.replaceFirst(
"(\\?|#|$).*", "?eagerInit#eagerInit")));
lazyInitLink.setTargetName("_blank");
layout.addComponent(lazyInitLink);
}
};
return uI;
}
}
public static Label getRequestInfo(String name, VaadinRequest request) {
String info = name;
info += "<br />pathInfo: " + request.getRequestPathInfo();
info += "<br />parameters: " + request.getParameterMap().keySet();
info += "<br />uri fragment: "
+ Page.getCurrent().getLocation().getFragment();
return new Label(info, ContentMode.HTML);
}
@Override
protected String getTestDescription() {
return "BrowserDetails should be available in Application.getUI if UIRequiresMoreInformation has been thrown and in UI.init if the UI has the @UIInitRequiresBrowserDetals annotation";
}
@Override
protected Integer getTicketNumber() {
return Integer.valueOf(7883); // + #7882 + #7884
}
}
|