You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2007/11/19 22:22:38 UTC

svn commit: r596453 - in /myfaces: core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java shared/trunk_3.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java

Author: manolito
Date: Mon Nov 19 13:22:37 2007
New Revision: 596453

URL: http://svn.apache.org/viewvc?rev=596453&view=rev
Log:
MYFACES-1700 each <h:form> generated an <input> with same id="javax.faces.ViewState"
(merged changes from JSF 1.1 trunk)

Modified:
    myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java
    myfaces/shared/trunk_3.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java

Modified: myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java?rev=596453&r1=596452&r2=596453&view=diff
==============================================================================
--- myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java (original)
+++ myfaces/core/trunk_1.2.x/impl/src/main/java/org/apache/myfaces/renderkit/html/HtmlResponseStateManager.java Mon Nov 19 13:22:37 2007
@@ -31,7 +31,6 @@
 import javax.faces.render.RenderKitFactory;
 import javax.faces.render.ResponseStateManager;
 import java.io.IOException;
-import java.util.Map;
 
 /**
  * @author Manfred Geiler (latest modification by $Author$)
@@ -102,16 +101,19 @@
     	String serializedState = StateUtils.construct(savedState,
                 facesContext.getExternalContext());
         ExternalContext extContext = facesContext.getExternalContext();
+        MyfacesConfig myfacesConfig = MyfacesConfig.getCurrentInstance(extContext);
         // Write Javascript viewstate if enabled and if javascript is allowed,
         // otherwise write hidden input
-        if (JavascriptUtils.isJavascriptAllowed(extContext) && MyfacesConfig.getCurrentInstance(extContext).isViewStateJavascript()) {
+        if (JavascriptUtils.isJavascriptAllowed(extContext) && myfacesConfig.isViewStateJavascript()) {
         	HtmlRendererUtils.renderViewStateJavascript(facesContext, STANDARD_STATE_SAVING_PARAM, serializedState);
         } else {
         	responseWriter.startElement(HTML.INPUT_ELEM, null);
         	responseWriter.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_HIDDEN, null);
         	responseWriter.writeAttribute(HTML.NAME_ATTR, STANDARD_STATE_SAVING_PARAM, null);
-        	responseWriter.writeAttribute(HTML.ID_ATTR, STANDARD_STATE_SAVING_PARAM, null);
-        	responseWriter.writeAttribute(HTML.VALUE_ATTR, serializedState, null);
+            if (myfacesConfig.isRenderViewStateId()) {
+                responseWriter.writeAttribute(HTML.ID_ATTR, STANDARD_STATE_SAVING_PARAM, null);
+            }
+            responseWriter.writeAttribute(HTML.VALUE_ATTR, serializedState, null);
         	responseWriter.endElement(HTML.INPUT_ELEM);
         }
     }

Modified: myfaces/shared/trunk_3.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java
URL: http://svn.apache.org/viewvc/myfaces/shared/trunk_3.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java?rev=596453&r1=596452&r2=596453&view=diff
==============================================================================
--- myfaces/shared/trunk_3.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java (original)
+++ myfaces/shared/trunk_3.0.x/core/src/main/java/org/apache/myfaces/shared/config/MyfacesConfig.java Mon Nov 19 13:22:37 2007
@@ -77,6 +77,9 @@
     private static final String  INIT_PARAM_VIEWSTATE_JAVASCRIPT = "org.apache.myfaces.VIEWSTATE_JAVASCRIPT";
     private static final boolean INIT_PARAM_VIEWSTATE_JAVASCRIPT_DEFAULT = false;
 
+    private static final String  INIT_PARAM_RENDER_VIEWSTATE_ID = "org.apache.myfaces.RENDER_VIEWSTATE_ID";
+    private static final boolean INIT_PARAM_RENDER_VIEWSTATE_ID_DEFAULT = true;
+
     private boolean _prettyHtml;
     private boolean _detectJavascript;
     private boolean _allowJavascript;
@@ -87,6 +90,7 @@
     private boolean _readonlyAsDisabledForSelect;
     private long _configRefreshPeriod;
     private boolean _viewStateJavascript;
+    private boolean _renderViewStateId;
 
 
     private static final boolean TOMAHAWK_AVAILABLE;
@@ -165,6 +169,8 @@
 
         myfacesConfig.setReadonlyAsDisabledForSelect(getBooleanInitParameter(extCtx, INIT_READONLY_AS_DISABLED_FOR_SELECT,
                                                                  INIT_READONLY_AS_DISABLED_FOR_SELECT_DEFAULT));
+        myfacesConfig.setRenderViewStateId(getBooleanInitParameter(extCtx, INIT_PARAM_RENDER_VIEWSTATE_ID,
+                                                            INIT_PARAM_RENDER_VIEWSTATE_ID_DEFAULT));
 
         myfacesConfig.setConfigRefreshPeriod(getLongInitParameter(extCtx, INIT_PARAM_CONFIG_REFRESH_PERIOD,
                 INIT_PARAM_CONFIG_REFRESH_PERIOD_DEFAULT));
@@ -327,6 +333,26 @@
    {
        _configRefreshPeriod = configRefreshPeriod;
    }
+
+    /**
+     * JSF API 1.2 defines a "javax.faces.ViewState" client parameter, that must be rendered as both the "name"
+     * and the "id" attribute of the hidden input that is rendered for the purpose of state saving
+     * (see <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/render/ResponseStateManager.html#VIEW_STATE_PARAM">API</a>).
+     * Actually this causes duplicate id attributes and thus invalid XHTML pages when multiple forms are rendered on
+     * one page. With the {@link #INIT_PARAM_RENDER_VIEWSTATE_ID} context parameter you can tune this behaviour.
+     * <br/>Set it to
+     * <ul><li>true - to render JSF 1.2 compliant id attributes (that might cause invalid XHTML), or</li>
+     * <li>false - to omit rendering of the id attribute (which is only needed for very special AJAX/Javascript components)</li></ul>
+     * Default value is: true (for backwards compatibility and JSF 1.2 compliancy) 
+     * @return true, if the client state hidden input "javax.faces.ViewState" id attribute should be rendered
+     */
+    public boolean isRenderViewStateId() {
+        return _renderViewStateId;
+    }
+
+    public void setRenderViewStateId(boolean renderViewStateId) {
+        _renderViewStateId = renderViewStateId;
+    }
 
     public boolean isTomahawkAvailable()
     {