From 98555d0eac757e738b9218cd0d8b719dd37ccc05 Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Wed, 14 Nov 2012 15:23:52 +0200 Subject: [PATCH] Added getState(boolean) to allow getState without side effects (#10006) Change-Id: Idee529a8efc245da88192cd059c9e35165d1adad --- .../server/AbstractClientConnector.java | 39 ++++++++++++++++--- .../src/com/vaadin/ui/AbstractComponent.java | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index 3762e90d05..ecdab22160 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -158,17 +158,44 @@ public abstract class AbstractClientConnector implements ClientConnector, registerRpc(implementation, type); } + /** + * Returns the shared state for this connector. The shared state object is + * shared between the server connector and the client connector. Changes are + * only communicated from the server to the client and not in the other + * direction. + *

+ * As a side effect, marks the connector dirty so any changes done to the + * state will be sent to the client. Use {@code getState(false)} to avoid + * marking the connector as dirty. + *

+ * + * @return The shared state for this connector. Never null. + */ protected SharedState getState() { + return getState(true); + } + + /** + * Returns the shared state for this connector. + * + * @param markAsDirty + * true if the connector should automatically be marked dirty, + * false otherwise + * + * @return The shared state for this connector. Never null. + * @see #getState() + */ + protected SharedState getState(boolean markAsDirty) { if (null == sharedState) { sharedState = createState(); } - - UI uI = getUI(); - if (uI != null && !uI.getConnectorTracker().isWritingResponse() - && !uI.getConnectorTracker().isDirty(this)) { - markAsDirty(); + if (markAsDirty) { + UI ui = getUI(); + if (ui != null && !ui.getConnectorTracker().isWritingResponse() + && !ui.getConnectorTracker().isDirty(this)) { + markAsDirty(); + } } - return sharedState; } diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java index 7e7a595a2e..f1924692ba 100644 --- a/server/src/com/vaadin/ui/AbstractComponent.java +++ b/server/src/com/vaadin/ui/AbstractComponent.java @@ -323,7 +323,7 @@ public abstract class AbstractComponent extends AbstractClientConnector */ @Override public boolean isEnabled() { - return getState().enabled; + return getState(false).enabled; } /* -- 2.39.5