You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/07/30 20:50:41 UTC

svn commit: r980922 - in /myfaces/core/trunk/api/src: main/java/javax/faces/component/UIInput.java main/java/javax/faces/component/_DeltaStateHelper.java test/java/javax/faces/component/_DeltaStateHelperTest.java

Author: lu4242
Date: Fri Jul 30 18:50:40 2010
New Revision: 980922

URL: http://svn.apache.org/viewvc?rev=980922&view=rev
Log:
MYFACES-2850 Clean saved state of UIInput (thanks to Marius Petoi for this patch)

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_DeltaStateHelper.java
    myfaces/core/trunk/api/src/test/java/javax/faces/component/_DeltaStateHelperTest.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java?rev=980922&r1=980921&r2=980922&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UIInput.java Fri Jul 30 18:50:40 2010
@@ -796,7 +796,14 @@ public class UIInput extends UIOutput im
 
     public void setValid(boolean valid)
     {
-        getStateHelper().put(PropertyKeys.valid, valid );
+        // default value for valid is true, so if the intention is to save the default
+        // value when nothing else was set before, don't do it. This is done in order to
+        // reduce the size of the saved state of the state helper. Default values won't be
+        // included in the saved state. 
+        if (getStateHelper().get(PropertyKeys.valid) != null || !valid)
+        {
+            getStateHelper().put(PropertyKeys.valid, valid );
+        }
     }
 
     /**
@@ -817,7 +824,14 @@ public class UIInput extends UIOutput im
 
     public void setLocalValueSet(boolean localValueSet)
     {
-        getStateHelper().put(PropertyKeys.localValueSet, localValueSet );
+        // default value for localValueSet is false, so if the intention is to save the default
+        // value when nothing else was set before, don't do it. This is done in order to
+        // reduce the size of the saved state of the state helper. Default values won't be
+        // included in the saved state.
+        if (getStateHelper().get(PropertyKeys.localValueSet) != null || localValueSet)
+        {
+            getStateHelper().put(PropertyKeys.localValueSet, localValueSet );
+        }
     }
 
     /**

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_DeltaStateHelper.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_DeltaStateHelper.java?rev=980922&r1=980921&r2=980922&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_DeltaStateHelper.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_DeltaStateHelper.java Fri Jul 30 18:50:40 2010
@@ -278,6 +278,10 @@ class _DeltaStateHelper implements State
                 returnValue = _deltas.put(key, value);
                 _fullState.put(key, value);
             }
+            else if (value == null && !_fullState.containsKey(key))
+            {
+                returnValue = null;
+            }
             else
             {
                 _deltas.put(key, value);

Modified: myfaces/core/trunk/api/src/test/java/javax/faces/component/_DeltaStateHelperTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/test/java/javax/faces/component/_DeltaStateHelperTest.java?rev=980922&r1=980921&r2=980922&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/test/java/javax/faces/component/_DeltaStateHelperTest.java (original)
+++ myfaces/core/trunk/api/src/test/java/javax/faces/component/_DeltaStateHelperTest.java Fri Jul 30 18:50:40 2010
@@ -185,6 +185,28 @@ public class _DeltaStateHelperTest exten
                 && entry.get(KEY_2_2).equals(VAL3));
     }
 
+    public void testPut_null()
+    {
+        _instance.put(KEY1, null);
+        _instance.put(KEY2, null);
+
+        assertNull("key1 is not null", _instance.get(KEY1));
+        assertNull("key2 is not null", _instance.get(KEY2));
+
+        _setupGetTests();
+        assertTrue("check for key1", _instance.get(KEY1).equals(VAL1));
+
+        Map entry = (Map) _instance.get(KEY2);
+        assertTrue("check for key2", _instance.get(KEY2) instanceof Map);
+
+        assertTrue("check for key2 structure", entry.size() == 2
+                && entry.get(KEY_2_1).equals(VAL2)
+                && entry.get(KEY_2_2).equals(VAL3));
+
+        _instance.put(KEY1, null);
+        assertNull("key1 is not null", _instance.get(KEY1));
+    }
+
     /**
      * Test of put method, of class _DeltaStateHelper.
      */