From 50665cb1d34c84bc478cd5306f6c6151fe4d0bc3 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 4 Dec 2012 16:41:49 +0200 Subject: Reset state before sending hierarchy event to removed connector (#10151) Change-Id: If4f3e23a1d58c9f1cec7fc7d5e4e3f470932162f --- .../com/vaadin/client/ApplicationConnection.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'client') diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 354d809622..5f90fe4c19 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -2035,6 +2035,31 @@ public class ApplicationConnection { private void recursivelyDetach(ServerConnector connector, List events) { + + /* + * Reset state in an attempt to keep it consistent with the + * hierarchy. No children and no parent is the initial situation + * for the hierarchy, so changing the state to its initial value + * is the closest we can get without data from the server. + * #10151 + */ + try { + Type stateType = AbstractConnector.getStateType(connector); + + // Empty state instance to get default property values from + Object defaultState = stateType.createInstance(); + + SharedState state = connector.getState(); + + for (Property property : stateType.getProperties()) { + property.setValue(state, + property.getValue(defaultState)); + } + } catch (NoDataException e) { + throw new RuntimeException("Can't reset state for " + + Util.getConnectorString(connector), e); + } + /* * Recursively detach children to make sure they get * setParent(null) and hierarchy change events as needed. -- cgit v1.2.3