if (this.mainWindow != null) {
throw new IllegalStateException("mainWindow has already been set");
}
- if (mainWindow.getApplication() == null) {
- mainWindow.setApplication(VaadinSession.getCurrent());
- } else if (mainWindow.getApplication() != VaadinSession.getCurrent()) {
+ if (mainWindow.getSession() == null) {
+ mainWindow.setSession(VaadinSession.getCurrent());
+ } else if (mainWindow.getSession() != VaadinSession.getCurrent()) {
throw new IllegalStateException(
"mainWindow is attached to another application");
}
}
legacyUINames.put(uI.getName(), uI);
- uI.setApplication(VaadinSession.getCurrent());
+ uI.setSession(VaadinSession.getCurrent());
}
/**
int paintedComponents = 0;
for (int i = 0; i < components.length; i++) {
Component c = components[i];
- if (c.getApplication() != null) {
+ if (c.getUI() != null && c.getUI().getSession() != null) {
target.addAttribute("component" + paintedComponents++, c);
} else {
Logger.getLogger(SourceIs.class.getName())
@Override
public String getConnectorId() {
if (connectorId == null) {
- if (getApplication() == null) {
+ if (getSession() == null) {
throw new RuntimeException(
"Component must be attached to an application when getConnectorId() is called for the first time");
}
- connectorId = getApplication().createConnectorId(this);
+ connectorId = getSession().createConnectorId(this);
}
return connectorId;
}
*
* @return The connector's application, or <code>null</code> if not attached
*/
- protected VaadinSession getApplication() {
+ protected VaadinSession getSession() {
UI uI = getUI();
if (uI == null) {
return null;
} else {
- return uI.getApplication();
+ return uI.getSession();
}
}
}
// Send detach event if the component have been connected to a window
- if (getApplication() != null) {
+ if (getSession() != null) {
detach();
}
this.parent = parent;
// Send attach event if connected to an application
- if (getApplication() != null) {
+ if (getSession() != null) {
attach();
}
}
* {@inheritDoc}
*
* <p>
- * The {@link #getApplication()} and {@link #getUI()} methods might return
+ * The {@link #getSession()} and {@link #getUI()} methods might return
* <code>null</code> after this method is called.
* </p>
*/
}
sb.append("\nComponent hierarchy:\n");
- VaadinSession application2 = component.getApplication();
+ VaadinSession application2 = component.getUI().getSession();
sb.append(application2.getClass().getName());
sb.append(".");
sb.append(application2.getClass().getSimpleName());
final PrintWriter outWriter, UI ui, boolean analyzeLayouts)
throws PaintException, JSONException {
ArrayList<ClientConnector> dirtyVisibleConnectors = new ArrayList<ClientConnector>();
- VaadinSession application = ui.getApplication();
+ VaadinSession application = ui.getSession();
// Paints components
ConnectorTracker uiConnectorTracker = ui.getConnectorTracker();
getLogger().log(Level.FINE, "* Creating response to client");
if (connector instanceof Component) {
errorComponent = (Component) connector;
}
- handleChangeVariablesError(uI.getApplication(),
+ handleChangeVariablesError(uI.getSession(),
errorComponent, realException, null);
}
} else {
errorComponent = (Component) dropHandlerOwner;
}
}
- handleChangeVariablesError(uI.getApplication(),
+ handleChangeVariablesError(uI.getSession(),
errorComponent, e, changes);
}
}
* Ends the Application.
*
* The browser is redirected to the Application logout URL set with
- * {@link VaadinSession#setLogoutURL(String)}, or to the application URL if no
- * logout URL is given.
+ * {@link VaadinSession#setLogoutURL(String)}, or to the application URL if
+ * no logout URL is given.
*
* @param request
* the request instance.
StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter(sWriter);
pWriter.print("{");
- if (isXSRFEnabled(uI.getApplication())) {
+ if (isXSRFEnabled(uI.getSession())) {
pWriter.print(getSecurityKeyUIDL(request));
}
writeUidlResponse(request, true, pWriter, uI, false);
protected InputStream getThemeResourceAsStream(UI uI, String themeName,
String resource) {
VaadinServletSession context = (VaadinServletSession) uI
- .getApplication();
+ .getSession();
ServletContext servletContext = context.getHttpSession()
.getServletContext();
return servletContext.getResourceAsStream("/"
}
UI.setCurrent(ui);
- VaadinSession.setCurrent(ui.getApplication());
+ VaadinSession.setCurrent(ui.getSession());
ClientConnector connector = ui.getConnectorTracker().getConnector(
cid);
throw new NullPointerException();
}
ClientConnector ownerConnector = openPaintables.peek();
- ownerConnector.getUI().getApplication().getGlobalResourceHandler(true)
+ ownerConnector.getUI().getSession().getGlobalResourceHandler(true)
.register(value, ownerConnector);
ResourceReference reference = ResourceReference.create(value,
}
public WebBrowser getWebBrowser() {
- return uI.getApplication().getBrowser();
+ return uI.getSession().getBrowser();
}
public void setBrowserWindowSize(int width, int height) {
protected InputStream getThemeResourceAsStream(UI uI, String themeName,
String resource) {
VaadinPortletSession context = (VaadinPortletSession) uI
- .getApplication();
+ .getSession();
PortletContext portletContext = context.getPortletSession()
.getPortletContext();
return portletContext.getResourceAsStream("/"
ConnectorResource connectorResource = (ConnectorResource) resource;
GlobalResourceHandler globalResourceHandler = connector.getUI()
- .getApplication().getGlobalResourceHandler(false);
+ .getSession().getGlobalResourceHandler(false);
if (globalResourceHandler != null) {
String uri = globalResourceHandler.getUri(connector,
connectorResource);
UI ui = createUIInstance(request, uiClass);
// Initialize some fields for a newly created UI
- if (ui.getApplication() == null) {
- ui.setApplication(this);
+ if (ui.getSession() == null) {
+ ui.setSession(this);
}
// Get the next id
Integer uiId = Integer.valueOf(nextUIId++);
if (parent != null) {
return parent.getLocale();
}
- final VaadinSession app = getApplication();
+ final VaadinSession app = getSession();
if (app != null) {
return app.getLocale();
}
*/
protected void focus() {
if (this instanceof Focusable) {
- final VaadinSession app = getApplication();
+ final VaadinSession app = getSession();
if (app != null) {
getUI().setFocusedComponent((Focusable) this);
delayedFocus = false;
}
}
- /**
- * Gets the application object to which the component is attached.
- *
- * <p>
- * The method will return {@code null} if the component is not currently
- * attached to an application. This is often a problem in constructors of
- * regular components and in the initializers of custom composite
- * components. A standard workaround is to move the problematic
- * initialization to {@link #attach()}, as described in the documentation of
- * the method.
- * </p>
- * <p>
- * <b>This method is not meant to be overridden. Due to CDI requirements we
- * cannot declare it as final even though it should be final.</b>
- * </p>
- *
- * @return the parent application of the component or <code>null</code>.
- * @see #attach()
- */
- @Override
- public VaadinSession getApplication() {
- // Just make method inherited from Component interface public
- return super.getApplication();
- }
-
/**
* Build CSS compatible string representation of height.
*
*/
public void setConverter(Class<?> datamodelType) {
Converter<T, ?> c = (Converter<T, ?>) ConverterUtil.getConverter(
- getType(), datamodelType, getApplication());
+ getType(), datamodelType, getSession());
setConverter(c);
}
import com.vaadin.server.ErrorMessage;
import com.vaadin.server.Resource;
import com.vaadin.server.Sizeable;
-import com.vaadin.server.VaadinSession;
import com.vaadin.server.VariableOwner;
/**
@Override
public UI getUI();
- /**
- * Gets the application object to which the component is attached.
- *
- * <p>
- * The method will return {@code null} if the component is not currently
- * attached to an application.
- * </p>
- *
- * <p>
- * Getting a null value is often a problem in constructors of regular
- * components and in the initializers of custom composite components. A
- * standard workaround is to use {@link VaadinSession#getCurrent()} to
- * retrieve the application instance that the current request relates to.
- * Another way is to move the problematic initialization to
- * {@link #attach()}, as described in the documentation of the method.
- * </p>
- *
- * @return the parent application of the component or <code>null</code>.
- * @see #attach()
- */
- public VaadinSession getApplication();
-
/**
* {@inheritDoc}
*
* <p>
* Reimplementing the {@code attach()} method is useful for tasks that need
* to get a reference to the parent, window, or application object with the
- * {@link #getParent()}, {@link #getUI()}, and {@link #getApplication()}
+ * {@link #getParent()}, {@link #getUI()}, and {@link #getSession()}
* methods. A component does not yet know these objects in the constructor,
* so in such case, the methods will return {@code null}. For example, the
* following is invalid:
}
private void removeFromGlobalResourceHandler(ClientConnector connector) {
- GlobalResourceHandler globalResourceHandler = uI.getApplication()
+ GlobalResourceHandler globalResourceHandler = uI.getSession()
.getGlobalResourceHandler(false);
// Nothing to do if there is no handler
if (globalResourceHandler != null) {
newDataSource.getType())) {
// Try to find a converter
Converter<String, ?> c = ConverterUtil.getConverter(String.class,
- newDataSource.getType(), getApplication());
+ newDataSource.getType(), getSession());
setConverter(c);
}
dataSource = newDataSource;
* @return byte array containing login page html
*/
protected byte[] getLoginHTML() {
- String appUri = getApplication().getURL().toString();
+ String appUri = getSession().getURL().toString();
try {
return ("<!DOCTYPE html PUBLIC \"-//W3C//DTD "
@Override
public void attach() {
super.attach();
- getApplication().addRequestHandler(requestHandler);
+ getSession().addRequestHandler(requestHandler);
iframe.setSource(loginPage);
}
@Override
public void detach() {
- getApplication().removeRequestHandler(requestHandler);
+ getSession().removeRequestHandler(requestHandler);
super.detach();
}
converter = getConverter(colId);
} else {
ConverterUtil.getConverter(String.class, property.getType(),
- getApplication());
+ getSession());
}
Object value = property.getValue();
if (converter != null) {
import java.util.LinkedHashSet;
import java.util.Map;
-import com.vaadin.LegacyApplication;
import com.vaadin.event.Action;
import com.vaadin.event.Action.Handler;
import com.vaadin.event.ActionManager;
public void setName(String name) {
this.name = name;
// The name can not be changed in application
- if (getApplication() != null) {
+ if (getSession() != null) {
throw new IllegalStateException(
"Window name can not be changed while "
+ "the window is in application");
* to an application
*/
public URL getURL() {
- VaadinSession application = getApplication();
+ VaadinSession application = getSession();
if (application == null) {
return null;
}
/**
* The application to which this UI belongs
*/
- private VaadinSession application;
+ private VaadinSession session;
/**
* List of windows in this UI.
throw new UnsupportedOperationException();
}
+ /**
+ * Gets the application object to which the component is attached.
+ *
+ * <p>
+ * The method will return {@code null} if the component is not currently
+ * attached to an application.
+ * </p>
+ *
+ * <p>
+ * Getting a null value is often a problem in constructors of regular
+ * components and in the initializers of custom composite components. A
+ * standard workaround is to use {@link VaadinSession#getCurrent()} to
+ * retrieve the application instance that the current request relates to.
+ * Another way is to move the problematic initialization to
+ * {@link #attach()}, as described in the documentation of the method.
+ * </p>
+ *
+ * @return the parent application of the component or <code>null</code>.
+ * @see #attach()
+ */
@Override
- public VaadinSession getApplication() {
- return application;
+ public VaadinSession getSession() {
+ return session;
}
@Override
* This method is mainly intended for internal use by the framework.
* </p>
*
- * @param application
+ * @param session
* the application to set
*
* @throws IllegalStateException
* if the application has already been set
*
- * @see #getApplication()
+ * @see #getSession()
*/
- public void setApplication(VaadinSession application) {
- if ((application == null) == (this.application == null)) {
+ public void setSession(VaadinSession session) {
+ if ((session == null) == (this.session == null)) {
throw new IllegalStateException("Application has already been set");
} else {
- if (application == null) {
+ if (session == null) {
detach();
}
- this.application = application;
+ this.session = session;
}
- if (application != null) {
+ if (session != null) {
attach();
}
}
* Gets the id of the UI, used to identify this UI within its application
* when processing requests. The UI id should be present in every request to
* the server that originates from this UI.
- * {@link VaadinSession#getUIForRequest(WrappedRequest)} uses this id to find
- * the route to which the request belongs.
+ * {@link VaadinSession#getUIForRequest(WrappedRequest)} uses this id to
+ * find the route to which the request belongs.
*
* @return
*/
throw new NullPointerException("Argument must not be null");
}
- if (window.getApplication() != null) {
+ if (window.getUI() != null && window.getUI().getSession() != null) {
throw new IllegalArgumentException(
"Window is already attached to an application.");
}
throw new IllegalStateException("UI id has already been defined");
}
this.uiId = uiId;
- theme = getApplication().getUiProvider(request, getClass())
+ theme = getSession().getUiProvider(request, getClass())
.getThemeForUI(request, getClass());
getPage().init(request);
TextField tf = new TextField("", "123") {
@Override
- public VaadinSession getApplication() {
+ public VaadinSession getSession() {
return appWithCustomIntegerConverter;
};
};
TextField tf = new TextField("", "123") {
@Override
- public VaadinSession getApplication() {
+ public VaadinSession getSession() {
return fieldAppWithCustomIntegerConverter;
}
};
}
@Override
- public VaadinSession getApplication() {
+ public VaadinSession getSession() {
return application;
}
};
VaadinSession.setCurrent(a);
TextField tf = new TextField() {
@Override
- public VaadinSession getApplication() {
+ public VaadinSession getSession() {
return a;
}
};
}
@Override
- public VaadinSession getApplication() {
+ public VaadinSession getSession() {
return application;
}
};
@Override
- public VaadinSession getApplication() {
+ public VaadinSession getSession() {
return application;
};
};
import org.junit.Test;
+import com.vaadin.server.ClientConnector;
import com.vaadin.server.VaadinSession;
import com.vaadin.server.WrappedRequest;
import com.vaadin.ui.Label;
public TestContent getTestContent();
- public VaadinSession getApplication();
+ public VaadinSession getSession();
}
private class TestWindow extends Window implements TestContainer {
public TestContent getTestContent() {
return testContent;
}
+
+ @Override
+ public VaadinSession getSession() {
+ return super.getSession();
+ }
}
private class TestContent extends VerticalLayout {
assertUnattached(sub);
// attaching main should recurse to sub
- main.setApplication(testApp);
+ main.setSession(testApp);
assertAttached(main);
assertAttached(sub);
}
assertUnattached(main);
assertUnattached(sub);
- main.setApplication(testApp);
+ main.setSession(testApp);
assertAttached(main);
assertUnattached(sub);
@Test
public void removeSubWindowBeforeDetachingMainWindow() {
- main.setApplication(testApp);
+ main.setSession(testApp);
main.addWindow(sub);
// sub should be detached when removing from attached main
assertDetached(sub);
// main detach should recurse to sub
- main.setApplication(null);
+ main.setSession(null);
assertDetached(main);
assertDetached(sub);
}
@Test
public void removeSubWindowAfterDetachingMainWindow() {
- main.setApplication(testApp);
+ main.setSession(testApp);
main.addWindow(sub);
// main detach should recurse to sub
- main.setApplication(null);
+ main.setSession(null);
assertDetached(main);
assertDetached(sub);
assertTrue("window child attach not called",
testContent.childAttachCalled);
- assertSame("window not attached", win.getApplication(), testApp);
- assertSame("window content not attached", testContent.getApplication(),
- testApp);
- assertSame("window children not attached",
- testContent.child.getApplication(), testApp);
+ assertSame("window not attached", win.getSession(), testApp);
+ assertSame("window content not attached", testContent.getUI()
+ .getSession(), testApp);
+ assertSame("window children not attached", testContent.child.getUI()
+ .getSession(), testApp);
}
/**
* Asserts that win and its children are not attached.
*/
private void assertUnattached(TestContainer win) {
- assertSame("window not detached", win.getApplication(), null);
- assertSame("window content not detached", win.getTestContent()
- .getApplication(), null);
+ assertSame("window not detached", win.getSession(), null);
+ assertSame("window content not detached",
+ getVaadinSession(win.getTestContent()), null);
assertSame("window children not detached",
- win.getTestContent().child.getApplication(), null);
+ getVaadinSession(win.getTestContent().child), null);
+ }
+
+ private VaadinSession getVaadinSession(ClientConnector testContainer) {
+ UI ui = testContainer.getUI();
+ if (ui != null) {
+ return ui.getSession();
+ } else {
+ return null;
+ }
}
/**
Button b = event.getButton();
System.out.println(b.getCaption() + " click: "
+ (new Date()).toString());
- System.out.println(b.getApplication());
+ System.out.println(b.getUI().getSession());
}
}));
@Override
public void buttonClick(ClickEvent event) {
- getApplication().close();
+ getSession().close();
}
});
main.addComponent(restart);
@Override
public void buttonClick(ClickEvent event) {
- event.getButton().getApplication().close();
+ event.getButton().getUI().getSession().close();
}
});
protected abstract Integer getTicketNumber();
protected WebBrowser getBrowser() {
- return getApplication().getBrowser();
+ return getSession().getBrowser();
}
}
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Label;
import com.vaadin.ui.ProgressIndicator;
-import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.Table;
+import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.VerticalLayout;
public class TableFirstRowFlicker extends LegacyApplication {
@Override
public void run() {
while (t != null) {
- synchronized (t.getApplication()) {
+ synchronized (t.getUI().getSession()) {
int firstId = t.getCurrentPageFirstItemIndex();
Object selected = t.getValue();
t.setContainerDataSource(buildContainer());
ml.addListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
- if (textField.getApplication() == null) {
+ if (textField.getUI() == null
+ || textField.getUI().getSession() == null) {
replaceComponent(textArea, textField);
activeComponent = textField;
} else {
restart.addListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
- mainLayout.getUI().getApplication().close();
+ mainLayout.getUI().getSession().close();
}
});
public class CustomConverterFactoryUI extends AbstractTestUI {
@Override
public void setup(WrappedRequest request) {
- getApplication().setConverterFactory(new MyConverterFactory());
+ getSession().setConverterFactory(new MyConverterFactory());
TextField tf = new TextField("This is my double field");
tf.setImmediate(true);
@Override
public void setup(WrappedRequest request) {
// Add the request handler that handles our dynamic image
- getApplication().addRequestHandler(new DynamicImageRequestHandler());
+ getSession().addRequestHandler(new DynamicImageRequestHandler());
// Create a URL that we can handle in DynamicImageRequestHandler
URL imageUrl;
try {
- imageUrl = new URL(getApplication().getURL(),
+ imageUrl = new URL(getSession().getURL(),
DynamicImageRequestHandler.IMAGE_URL + "?text=Hello!");
} catch (MalformedURLException e) {
// This should never happen