]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added getState(boolean) to allow getState without side effects (#10006) 68/268/5
authorMikael Grankvist <mgrankvi@vaadin.com>
Wed, 14 Nov 2012 13:23:52 +0000 (15:23 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 20 Nov 2012 13:31:39 +0000 (13:31 +0000)
Change-Id: Idee529a8efc245da88192cd059c9e35165d1adad

server/src/com/vaadin/server/AbstractClientConnector.java
server/src/com/vaadin/ui/AbstractComponent.java

index 3762e90d05a2f184bf02fdfefd525b6e1680e613..ecdab221603b573e1201b26659d0e6daff94ec45 100644 (file)
@@ -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.
+     * <p>
+     * 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.
+     * </p>
+     * 
+     * @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;
     }
 
index 7e7a595a2eaeaa73e4451358eaac2023b5cc32c2..f1924692ba41a62a51f0b12cb5cd0407bdce340c 100644 (file)
@@ -323,7 +323,7 @@ public abstract class AbstractComponent extends AbstractClientConnector
      */
     @Override
     public boolean isEnabled() {
-        return getState().enabled;
+        return getState(false).enabled;
     }
 
     /*