You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/08/26 18:17:14 UTC

svn commit: r989805 - /myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java

Author: lofwyr
Date: Thu Aug 26 16:17:14 2010
New Revision: 989805

URL: http://svn.apache.org/viewvc?rev=989805&view=rev
Log:
TOBAGO-909: Postback detection fails with JSF Impl 1.1.01 and MyFaces 1.1.4
 - Checking if the state will be rendered, if not write the hidden field explicitly

Modified:
    myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java

Modified: myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java?rev=989805&r1=989804&r2=989805&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java (original)
+++ myfaces/tobago/branches/tobago-1.0.x/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/PageRenderer.java Thu Aug 26 16:17:14 2010
@@ -22,31 +22,20 @@ package org.apache.myfaces.tobago.render
  * $Id$
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.StringUtils;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DELAY;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DOCTYPE;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ENCTYPE;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_METHOD;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_PAGE_MENU;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TARGET;
-import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TRANSITION;
-import static org.apache.myfaces.tobago.TobagoConstants.FACET_ACTION;
-import static org.apache.myfaces.tobago.TobagoConstants.FACET_MENUBAR;
-import static org.apache.myfaces.tobago.TobagoConstants.FACET_RESIZE_ACTION;
-import static org.apache.myfaces.tobago.TobagoConstants.FORM_ACCEPT_CHARSET;
-import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
 import org.apache.myfaces.tobago.component.ComponentUtil;
+import org.apache.myfaces.tobago.component.UIForm;
 import org.apache.myfaces.tobago.component.UILayout;
 import org.apache.myfaces.tobago.component.UIPage;
 import org.apache.myfaces.tobago.component.UIPopup;
-import org.apache.myfaces.tobago.component.UIForm;
 import org.apache.myfaces.tobago.context.ClientProperties;
 import org.apache.myfaces.tobago.context.ResourceManagerUtil;
+import org.apache.myfaces.tobago.model.PageState;
 import org.apache.myfaces.tobago.renderkit.PageRendererBase;
 import org.apache.myfaces.tobago.renderkit.RenderUtil;
+import org.apache.myfaces.tobago.renderkit.TobagoResponseStateManager;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.HtmlRendererUtil;
@@ -55,13 +44,12 @@ import org.apache.myfaces.tobago.util.Fa
 import org.apache.myfaces.tobago.util.MimeTypeUtils;
 import org.apache.myfaces.tobago.util.ResponseUtils;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
-import org.apache.myfaces.tobago.model.PageState;
 
 import javax.faces.application.Application;
 import javax.faces.application.FacesMessage;
 import javax.faces.application.ViewHandler;
-import javax.faces.component.UIComponent;
 import javax.faces.component.UICommand;
+import javax.faces.component.UIComponent;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -74,6 +62,20 @@ import java.util.Map;
 import java.util.Set;
 import java.util.StringTokenizer;
 
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DELAY;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_DOCTYPE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_ENCTYPE;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_LABEL;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_METHOD;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_PAGE_MENU;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TARGET;
+import static org.apache.myfaces.tobago.TobagoConstants.ATTR_TRANSITION;
+import static org.apache.myfaces.tobago.TobagoConstants.FACET_ACTION;
+import static org.apache.myfaces.tobago.TobagoConstants.FACET_MENUBAR;
+import static org.apache.myfaces.tobago.TobagoConstants.FACET_RESIZE_ACTION;
+import static org.apache.myfaces.tobago.TobagoConstants.FORM_ACCEPT_CHARSET;
+import static org.apache.myfaces.tobago.TobagoConstants.SUBCOMPONENT_SEP;
+
 public class PageRenderer extends PageRendererBase {
 
   private static final Log LOG = LogFactory.getLog(PageRenderer.class);
@@ -497,7 +499,30 @@ public class PageRenderer extends PageRe
     writer.startElement(HtmlConstants.SPAN, null);
     writer.writeIdAttribute(clientId + SUBCOMPONENT_SEP + "jsf-state-container");
     writer.flush();
+
+    // catch the next written stuff into a string and look if it is empty (TOBAGO-909)
+    FastStringWriter buffer = new FastStringWriter(40); // usually only the marker...
+    TobagoResponseWriter originalWriter = (TobagoResponseWriter) facesContext.getResponseWriter();
+    writer = (TobagoResponseWriter) writer.cloneWithWriter(buffer);
+    facesContext.setResponseWriter(writer);
     viewHandler.writeState(facesContext);
+    final String stateContent = buffer.toString();
+    writer = originalWriter;
+    facesContext.setResponseWriter(writer);
+
+    if (StringUtils.isBlank(stateContent)) {
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("Writing state will not happen! So we write the hidden field manually.");
+      }
+      writer.startElement(HtmlConstants.INPUT, null);
+      writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
+      writer.writeAttribute(HtmlAttributes.NAME, TobagoResponseStateManager.TREE_PARAM, false);
+      writer.writeAttribute(HtmlAttributes.ID, TobagoResponseStateManager.TREE_PARAM, false);
+      writer.writeAttribute(HtmlAttributes.VALUE, "workaround", false);
+      writer.endElement(HtmlConstants.INPUT);
+    } else {
+      writer.write(stateContent);
+    }
     writer.endElement(HtmlConstants.SPAN);
 
 //    facesContext.getApplication().getViewHandler().writeState(facesContext);