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 2015/04/01 03:32:16 UTC

svn commit: r1670537 - /myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java

Author: lu4242
Date: Wed Apr  1 01:32:15 2015
New Revision: 1670537

URL: http://svn.apache.org/r1670537
Log:
MYFACES-3949 javax.faces.ViewState autocomplete

Modified:
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java?rev=1670537&r1=1670536&r2=1670537&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java Wed Apr  1 01:32:15 2015
@@ -67,13 +67,24 @@ public class HtmlResponseStateManager ex
     public static final String INIT_PARAM_HANDLE_STATE_CACHING_MECHANICS
             = "org.apache.myfaces.HANDLE_STATE_CACHING_MECHANICS";
     
+    /**
+     * Add autocomplete="off" to the view state hidden field. Enabled by default.
+     */
+    @JSFWebConfigParam(since="2.2.8, 2.1.18, 2.0.24", expectedValues="true, false", 
+           defaultValue="true", group="state")
+    public static final String INIT_PARAM_AUTOCOMPLETE_OFF_VIEW_STATE = 
+            "org.apache.myfaces.AUTOCOMPLETE_OFF_VIEW_STATE";
+    
     private Boolean _handleStateCachingMechanics;
     
     private StateCacheFactory _stateCacheFactory;
     
+    private Boolean _autoCompleteOffViewState;
+    
     public HtmlResponseStateManager()
     {
         _stateCacheFactory = new StateCacheFactoryImpl();
+        _autoCompleteOffViewState = null;
     }
     
     protected boolean isHandlingStateCachingMechanics(FacesContext facesContext)
@@ -173,6 +184,10 @@ public class HtmlResponseStateManager ex
                 responseWriter.writeAttribute(HTML.ID_ATTR, STANDARD_STATE_SAVING_PARAM, null);
             }
             responseWriter.writeAttribute(HTML.VALUE_ATTR, serializedState, null);
+            if (this.isAutocompleteOffViewState(facesContext))
+            {
+                responseWriter.writeAttribute(HTML.AUTOCOMPLETE_ATTR, "off", null);
+            }
             responseWriter.endElement(HTML.INPUT_ELEM);
         }
     }
@@ -343,5 +358,14 @@ public class HtmlResponseStateManager ex
     {
         return _stateCacheFactory.getStateCache(facesContext);
     }
-
+    
+    private boolean isAutocompleteOffViewState(FacesContext facesContext)
+    {
+        if (_autoCompleteOffViewState == null)
+        {
+            _autoCompleteOffViewState = WebConfigParamUtils.getBooleanInitParameter(facesContext.getExternalContext(),
+                    INIT_PARAM_AUTOCOMPLETE_OFF_VIEW_STATE, true);
+        }
+        return _autoCompleteOffViewState;
+    }
 }