From 94dd167211592e3a21ef80addb88fe00967a36c8 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 24 Sep 2012 16:01:35 +0300 Subject: Add UI id to UICreateEvent for use in createInstance (#9721) --- .../server/AbstractCommunicationManager.java | 5 ++-- server/src/com/vaadin/server/UICreateEvent.java | 35 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index ed3b73dc20..b5237438ba 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -2525,9 +2525,11 @@ public abstract class AbstractCommunicationManager implements Serializable { // No existing UI found - go on by creating and initializing one + Integer uiId = Integer.valueOf(session.getNextUIid()); + // Explicit Class.cast to detect if the UIProvider does something // unexpected - UICreateEvent event = new UICreateEvent(request, uiClass); + UICreateEvent event = new UICreateEvent(request, uiClass, uiId); UI ui = uiClass.cast(provider.createInstance(event)); // Initialize some fields for a newly created UI @@ -2535,7 +2537,6 @@ public abstract class AbstractCommunicationManager implements Serializable { // Session already set for LegacyWindow ui.setSession(session); } - Integer uiId = Integer.valueOf(session.getNextUIid()); // Set thread local here so it is available in init UI.setCurrent(ui); diff --git a/server/src/com/vaadin/server/UICreateEvent.java b/server/src/com/vaadin/server/UICreateEvent.java index 561bc4cdfa..a608b5eb19 100644 --- a/server/src/com/vaadin/server/UICreateEvent.java +++ b/server/src/com/vaadin/server/UICreateEvent.java @@ -28,9 +28,11 @@ import com.vaadin.ui.UI; public class UICreateEvent extends UIProviderEvent { private final Class uiClass; + private final Integer uiId; /** - * Creates a new UI create event for a given VaadinRequest and UI class. + * Creates a new UI create event for a given VaadinRequest and UI class but + * without a UI id. * * @param request * the request for which the UI will be created @@ -38,8 +40,26 @@ public class UICreateEvent extends UIProviderEvent { * the UI class that will be created */ public UICreateEvent(VaadinRequest request, Class uiClass) { + this(request, uiClass, null); + } + + /** + * Creates a new UI create event for a given VaadinRequest, UI class and UI + * id + * + * @param request + * the request for which the UI will be created + * @param uiClass + * the UI class that will be created + * @param uiId + * the id reserved for the UI; or null if no id has + * yet been allocated. + */ + public UICreateEvent(VaadinRequest request, Class uiClass, + Integer uiId) { super(request); this.uiClass = uiClass; + this.uiId = uiId; } /** @@ -51,4 +71,17 @@ public class UICreateEvent extends UIProviderEvent { return uiClass; } + /** + * Gets the id of the UI about to be created. This might be + * null if the id has not yet been determined. + *

+ * The UI id is generally only available in + * {@link UIProvider#createInstance(UICreateEvent)} + * + * @return the UI id; or null if the UI id is not yet known. + */ + public Integer getUiId() { + return uiId; + } + } -- cgit v1.2.3