Author: gvanmatre
Date: Wed Aug 24 21:44:52 2005
New Revision: 239992

URL: http://svn.apache.org/viewcvs?rev=239992&view=rev
Log:
Bug#:  35212  - Clay doesn't process transient components correctly; patch 
submitted by Manfred Klug
 
Bug#:  35764  - [shale] Clay View-Handler doesn't work correctly with client 
side state saving.

Added:
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/FalseLookupCommand.java
Modified:
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/shale-clay-config.xml
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java
    
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties 
(original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties 
Wed Aug 24 21:44:52 2005
@@ -71,7 +71,9 @@
 
 #org.apache.shale.clay.component.chain.CreateComponentCommand
 create.component.error=Cannot create Component {0}
-create.component.exists=Child component {0} is already created.
+create.component=Child component id: {0}, jsfid: {1} child#: {2} created.
+create.facet.component=Facet component {0}, jsfid: {1} created.
+create.component.exists=Child component {0}, jsfid: {1} child#: {2} exists.
 
 #org.apache.shale.clay.component.chain.CreateConverterCommand
 create.converter.error=Cannot create Converter {0}

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/Clay.java
 Wed Aug 24 21:44:52 2005
@@ -135,23 +135,6 @@
 
     /**
      * <p>
-     * The output from UIViewRoot.createUniqueId() after the
-     * component tree has been constructed.
-     */
-    private String lastUniqueId = null;
-    
-    public void setlastUniqueId(String newId)
-    {
-        lastUniqueId = newId;
-    }
-
-    public String getlastUniqueId()
-    {
-        return lastUniqueId;
-    }
-
-    /**
-     * <p>
      * Returns the unique identifier used to build the component subtree
      * </p>
      */
@@ -245,22 +228,12 @@
         if (log.isTraceEnabled())
             log.trace("encodeBegin(FacesContext)");
         
-        if (getDisplayElementRoot() != null) {
-            // Call UIViewRoot.createUniqueId() until we have reproduced all
-            // IDs used during construction.
-            String currId = getFacesContext().getViewRoot().createUniqueId();
-            String lastId = this.getlastUniqueId();
-            while(!lastId.equals(currId)) {
-                currId = getFacesContext().getViewRoot().createUniqueId();
-            }
-        }
-        else {
+        if (getDisplayElementRoot() == null) {
             if (!getJsfid().equals(Globals.RUNTIME_ELEMENT_ID)) {
                 displayElementRoot = getRootElement();
             } else {
                 displayElementRoot = new ComponentBean();
-                displayElementRoot
-                        .setComponentType("javax.faces.HtmlOutputText");
+                
displayElementRoot.setComponentType("javax.faces.HtmlOutputText");
                 displayElementRoot.setJsfid(getJsfid());
                 
             }
@@ -281,58 +254,55 @@
                 
                 String expr = AbstractCommand.replaceMnemonic(clayContext);
                 Class[] methodSignature = {
-                    javax.faces.context.FacesContext.class,
-                            javax.faces.component.UIComponent.class,
-                            java.lang.Object.class };
-                            
-                            MethodBinding binding = 
getFacesContext().getApplication()
-                            .createMethodBinding(expr, methodSignature);
-                            
-                            if (log.isDebugEnabled()) {
-                                log
-                                        .debug(messages
-                                        
.getMessage("clay.invoke.shapeValidator"));
-                            }
-                            
-                            Object[] args = { context, this, 
displayElementRoot };
-                            binding.invoke(context, args);
-                            
-            }
-            
-            // Recursively build the subtree and fixup references. The root
-            // of the subview will be assinged to the child private property.
-            
-            ClayContext clayContext = new ClayContext();
-            clayContext.setChild(null);
-            clayContext.setDisplayElement(getDisplayElementRoot());
-            clayContext.setJsfid(getJsfid());
-            clayContext.setFacesContext(getFacesContext());
-            clayContext.setManagedBeanName(getManagedBeanName());
-            clayContext.setRootElement(getDisplayElementRoot());
-            clayContext.setParent(this);
-            
-            Catalog catalog = null;
-            try {
-                catalog = getCatalog();
-            } catch (Exception e) {
-                log.error(e);
-            }
-            Command command = catalog
-                    .getCommand(Globals.ADD_COMPONENT_COMMAND_NAME);
-            
-            try {
-                command.execute(clayContext);
-            } catch (Exception e) {
-                log.error(e);
-                throw new RuntimeException(e);
+                        javax.faces.context.FacesContext.class,
+                        javax.faces.component.UIComponent.class,
+                        java.lang.Object.class };
+                
+                MethodBinding binding = getFacesContext().getApplication()
+                    .createMethodBinding(expr, methodSignature);
+                
+                if (log.isDebugEnabled()) {
+                    log
+                    .debug(messages
+                            .getMessage("clay.invoke.shapeValidator"));
+                }
+                
+                Object[] args = { context, this, displayElementRoot };
+                binding.invoke(context, args);
+                
             }
-            
-            setlastUniqueId(getFacesContext().getViewRoot().createUniqueId());
-            
         }
         
+        // Recursively build the subtree and fixup references. The root
+        // of the subview will be assinged to the child private property.
+        
+        ClayContext clayContext = new ClayContext();
+        clayContext.setChild(null);
+        clayContext.setDisplayElement(getDisplayElementRoot());
+        clayContext.setJsfid(getJsfid());
+        clayContext.setFacesContext(getFacesContext());
+        clayContext.setManagedBeanName(getManagedBeanName());
+        clayContext.setRootElement(getDisplayElementRoot());
+        clayContext.setParent(this);
+        
+        Catalog catalog = null;
+        try {
+            catalog = getCatalog();
+        } catch (Exception e) {
+            log.error(e);
+        }
+        Command command = catalog
+        .getCommand(Globals.ADD_COMPONENT_COMMAND_NAME);
+        
+        try {
+            command.execute(clayContext);
+        } catch (Exception e) {
+            log.error(e);
+            throw new RuntimeException(e);
+        }
+            
     }
-    
+        
     /**
      * <p>
      * Recursively invokes the rendering of the sub component tree.
@@ -370,7 +340,7 @@
         
         if (log.isTraceEnabled())
             log.trace("encodeChildren(FacesContext)");
-
+        
         recursiveRenderChildren(this, context);
 
     }
@@ -386,7 +356,7 @@
         if (log.isTraceEnabled())
             log.trace("encodeEnd(FacesContext)");
         
-    }
+        }
     
     /**
      * <p>
@@ -425,7 +395,6 @@
         managedBeanName = ((String) aobj[2]);
         shapeValidator = ((String) aobj[3]);
         displayElementRoot = ((ComponentBean) aobj[4]);
-        lastUniqueId = ((String)aobj[5]);
         
     }
     
@@ -437,17 +406,16 @@
      * @see 
javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
      */
     public Object saveState(FacesContext context) {
-        Object[] aobj = new Object[6];
+        Object[] aobj = new Object[5];
         aobj[0] = super.saveState(context);
         aobj[1] = jsfid;
         aobj[2] = managedBeanName;
         aobj[3] = shapeValidator;
         aobj[4] = displayElementRoot;
-        aobj[5] = lastUniqueId;
         
         return aobj;
     }
-
+    
     /**
      * <p>Returns <code>true</code> indicating that this
      * component will render it's children.  This will 
@@ -457,7 +425,7 @@
      */
     public boolean getRendersChildren() {
        return true;
-    }
+}
 
     
 }

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/AssignChildrenCommand.java
 Wed Aug 24 21:44:52 2005
@@ -61,8 +61,8 @@
             throw new NullPointerException(messages
                     .getMessage("clay.null.clayContext"));
         
-        UIComponent child = (UIComponent) clayContext.getChild();
-        if (child == null)
+        UIComponent parent = (UIComponent) clayContext.getChild();
+        if (parent == null)
             throw new NullPointerException(messages
                     .getMessage("clay.null.childComponent"));
         
@@ -72,19 +72,26 @@
                     .getMessage("clay.null.componentBean"));
         
         Iterator vi = displayElement.getChildrenIterator();
+        int childIndex = 0;
         while (vi.hasNext()) {
             ComponentBean childDisplayElement = (ComponentBean) vi.next();
             
             ClayContext subContext = (ClayContext) clayContext.clone();
             subContext.setDisplayElement(childDisplayElement);
-            subContext.setParent(child);
+            subContext.setParent(parent);
             subContext.setChild(null);
+            subContext.setChildIndex(childIndex);
             
             Catalog catalog = getCatalog();
             Command command = catalog
                     .getCommand(Globals.ADD_COMPONENT_COMMAND_NAME);
             command.execute(subContext);
             
+            UIComponent child = (UIComponent)subContext.getChild();
+            
+            // Increment the index if the new component is not a facet
+            if (parent.getChildren().contains(child))
+                ++childIndex;
         }
         
         return isFinal;

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/ClayContext.java
 Wed Aug 24 21:44:52 2005
@@ -64,7 +64,7 @@
      * <p>Unique identifier for a component metadata definition.</p>
      */
     private String jsfid = null;
-    
+
     /**
      * <p>Returns the unique identifier for a component metadata definition</p>
      */
@@ -226,5 +226,27 @@
     public void setParent(UIComponent parent) {
         this.parent = parent;
     }
-    
+
+    /**
+     * <p>Index at which a new component must be added in the list of 
childs.</p> 
+     */
+    private int childIndex = 0;
+
+    /**
+     * <p>Returns the index at which a new component must be added in the list
+     * of childs.</p> 
+     */
+    public int getChildIndex()
+    {
+        return childIndex;
+    }
+
+    /**
+     * <p>Sets the index at which a new component must be added in the list
+     * of childs.</p> 
+     */
+    public void setChildIndex(int index)
+    {
+        childIndex = index;
+    }
 }

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/CreateComponentCommand.java
 Wed Aug 24 21:44:52 2005
@@ -83,6 +83,7 @@
             child = parent.getFacet(displayElement.getFacetName());
         else
             child = parent.findComponent(id);
+        
         if (child == null) {
             try {
                 child = facesContext.getApplication().createComponent(
@@ -94,24 +95,36 @@
             }
             
             child.setId(id);
-            if (displayElement.getFacetName() != null)
+            if (displayElement.getFacetName() != null) {
                 parent.getFacets().put(displayElement.getFacetName(), child);
-            else
-                parent.getChildren().add(parent.getChildren().size(), child);
-            
-            // reassign the child to the converter for the
-            // AssignPropertiesCommand
-            clayContext.setChild(child);
+                
+                if (log.isDebugEnabled())
+                    log.debug(messages.getMessage("create.facet.component",
+                        new Object[] { id, displayElement.getJsfid()}));
+
+            } else {
+                parent.getChildren().add(clayContext.getChildIndex(), child);
+                
+                if (log.isDebugEnabled())
+                    log.debug(messages.getMessage("create.component",
+                        new Object[] { id, displayElement.getJsfid(), new 
Integer(clayContext.getChildIndex()) }));
+
+            }
             
             // continue with the addComponent chain
             isFinal = false;
         } else {
             if (log.isDebugEnabled())
                 log.debug(messages.getMessage("create.component.exists",
-                        new Object[] { displayElement.getJsfid() }));
+                    new Object[] { id, displayElement.getJsfid(), new 
Integer(clayContext.getChildIndex()) }));
         }
         
+        // reassign the child to the converter for the
+        // AssignPropertiesCommand
+        clayContext.setChild(child);
+        
         return isFinal;
     }
+   
     
 }

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/shale-clay-config.xml
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/shale-clay-config.xml?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/shale-clay-config.xml
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/component/chain/shale-clay-config.xml
 Wed Aug 24 21:44:52 2005
@@ -1,81 +1,92 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-
-  Copyright 2005-2005 The Apache Software Foundation.
- 
-  Licensed under the Apache License, Version 2.0 (the "License");
-  you may not use this file except in compliance with the License.
-  You may obtain a copy of the License at
- 
-      http://www.apache.org/licenses/LICENSE-2.0
- 
-  Unless required by applicable law or agreed to in writing, software
-  distributed under the License is distributed on an "AS IS" BASIS,
-  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  See the License for the specific language governing permissions and
-  limitations under the License.
-
-  $Id$
-
--->
-
-<catalog           name="clay">
-
-  <chain           name="addComponent">
-
-    <command  
className="org.apache.shale.clay.component.chain.CreateComponentCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignValidatorsCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignValueChangeListenersCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignActionListenersCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignConverterCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignChildrenCommand"/>
-               
-  </chain>
-
-
-  <chain           name="addConverter">
-
-    <command  
className="org.apache.shale.clay.component.chain.CreateConverterCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
-
-  </chain>
-
-
-  <chain           name="addValidator">
-
-    <command  
className="org.apache.shale.clay.component.chain.CreateValidatorCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
-
-  </chain>
-
-
-  <chain           name="addValueChangeListener">
-
-    <command  
className="org.apache.shale.clay.component.chain.CreateValueChangeListenerCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
-
-  </chain>
-
-
-  <chain           name="addActionListener">
-
-    <command  
className="org.apache.shale.clay.component.chain.CreateActionListenerCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
-
-  </chain>
-
-
-  <chain           name="setAttribute">
-
-    <command  
className="org.apache.shale.clay.component.chain.PropertyActionCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.PropertyActionListenerCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.PropertyValidatorCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.PropertyValueChangeListenerCommand"/>
-    <command  
className="org.apache.shale.clay.component.chain.PropertyValueCommand"/>
-
-  </chain>
-
-
-</catalog>
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+
+  Copyright 2005-2005 The Apache Software Foundation.
+ 
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+  $Id$
+
+-->
+
+<catalog           name="clay">
+
+  <chain           name="addComponent">
+
+    <command className   = "org.apache.shale.clay.utils.FalseLookupCommand"
+             catalogName = "clay"
+             name        = "createComponent"
+             optional    = "false"/>
+             
+    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignChildrenCommand"/>
+               
+  </chain>
+
+
+  <chain           name="createComponent">
+
+    <command  
className="org.apache.shale.clay.component.chain.CreateComponentCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignValidatorsCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignValueChangeListenersCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignActionListenersCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignConverterCommand"/>
+
+  </chain>
+
+
+  <chain           name="addConverter">
+
+    <command  
className="org.apache.shale.clay.component.chain.CreateConverterCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
+
+  </chain>
+
+
+  <chain           name="addValidator">
+
+    <command  
className="org.apache.shale.clay.component.chain.CreateValidatorCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
+
+  </chain>
+
+
+  <chain           name="addValueChangeListener">
+
+    <command  
className="org.apache.shale.clay.component.chain.CreateValueChangeListenerCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
+
+  </chain>
+
+
+  <chain           name="addActionListener">
+
+    <command  
className="org.apache.shale.clay.component.chain.CreateActionListenerCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.AssignPropertiesCommand"/>
+
+  </chain>
+
+
+  <chain           name="setAttribute">
+
+    <command  
className="org.apache.shale.clay.component.chain.PropertyActionCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.PropertyActionListenerCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.PropertyValidatorCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.PropertyValueChangeListenerCommand"/>
+    <command  
className="org.apache.shale.clay.component.chain.PropertyValueCommand"/>
+
+  </chain>
+
+
+</catalog>

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/faces/ClayViewHandler.java
 Wed Aug 24 21:44:52 2005
@@ -18,6 +18,7 @@
 package org.apache.shale.clay.faces;
 
 import java.io.IOException;
+import java.io.StringWriter;
 import java.util.Iterator;
 import java.util.Locale;
 
@@ -183,6 +184,29 @@
     }
     
     /**
+     * <p>HTML form markers for client side state saving for MyFaces and Sun 
RI 
+     * implementations.</p> 
+     */
+    protected static final String[] FORM_MAKKERS = 
{"com.sun.faces.saveStateFieldMarker", "<!--@@JSF_FORM_STATE_MARKER@@-->"};
+    
+    /**
+     * <p>Returns an index into the <code>FORM_MAKKERS</code> array.  The 
index will be used to
+     * get the form marker matching the JSF runtime. Only the myfaces and Sun 
RI are supported.
+     * The form marker is determined by trying to load the myfaces view 
handler.  The default 
+     * is the marker for the Sun RI</p>
+     */
+    protected int indexOfFormMarker() {
+        int i = 0;
+        try {
+            
Class.forName("org.apache.myfaces.application.jsp.JspViewHandlerImpl");
+            i = 1;
+        } catch (ClassNotFoundException e) {
+        }
+
+        return i;
+    }
+    
+    /**
      * <p>The <code>viewId</code> of the view will be check to see if it ends 
with the 
      * same suffix as the configured clay-template-suffix.  If a match is not 
found, 
      * control is passed to the decorated view handler.  Otherwise, a [EMAIL 
PROTECTED] Clay} component 
@@ -218,23 +242,52 @@
             //set the locale
             (response).setLocale(context.getViewRoot().getLocale());
             
-            //create a response writer
-            ResponseWriter responsewriter = 
context.getRenderKit().createResponseWriter(response.getWriter(), null, 
response.getCharacterEncoding());
-            //push it to the faces context
-            context.setResponseWriter(responsewriter);
+            //builds a buffer to write the page to
+            StringWriter writer = new StringWriter();
+            //create a buffered response writer
+            ResponseWriter buffResponsewriter = 
context.getRenderKit().createResponseWriter(writer, null, 
response.getCharacterEncoding());
+            //push buffered writer to the faces context
+            context.setResponseWriter(buffResponsewriter);
             //start a document
-            responsewriter.startDocument();
+            buffResponsewriter.startDocument();
       
             recursiveRender(view, context);
 
             //end the document
-            responsewriter.endDocument();
+            buffResponsewriter.endDocument();
 
             //save the view 
             StateManager stateManager = 
context.getApplication().getStateManager();
             StateManager.SerializedView serializedview = 
stateManager.saveSerializedView(context);
-
            
+            ResponseWriter responsewriter = 
context.getRenderKit().createResponseWriter(response.getWriter(), null, 
response.getCharacterEncoding());
+            //push response writer to the faces context
+            context.setResponseWriter(responsewriter);
+            
+            StringBuffer buff = writer.getBuffer();
+            if (stateManager.isSavingStateInClient(context)) {
+                int curPos = 0;   // current position
+                int fndPos = 0;   //start of a marker
+                int frmMkrIdx = indexOfFormMarker();
+
+                //might be multiple forms in the document 
+                do {
+                    fndPos = buff.indexOf(FORM_MAKKERS[frmMkrIdx], curPos);
+                    if (fndPos > -1) {
+                        responsewriter.write(buff.substring(curPos, fndPos));
+                        stateManager.writeState(context, serializedview);
+                        curPos = fndPos + FORM_MAKKERS[frmMkrIdx].length();
+                    } else {
+                        responsewriter.write(buff.substring(curPos));
+                    }
+                } while(curPos < buff.length() && fndPos > -1);
+                
+                
+            } else {
+               //using server side state no need to look for form markers
+               responsewriter.write(buff.toString());    
+            }
+
         } else {
            //dispatch (forward) to the jsp
            original.renderView(context, view);

Modified: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java?rev=239992&r1=239991&r2=239992&view=diff
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java
 (original)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/VerbatimBuilder.java
 Wed Aug 24 21:44:52 2005
@@ -73,6 +73,8 @@
         
         attr.setUseValueLateBinding(Boolean.FALSE.toString());
         createAttribute("escape", Boolean.FALSE.toString(), target);
+        createAttribute("isTransient", Boolean.TRUE.toString(), target);
+
         
     }
  
@@ -109,6 +111,8 @@
             attr = createAttribute("value", tmp.toString(), endTarget);
             attr.setUseValueLateBinding(Boolean.FALSE.toString());
             createAttribute("escape", Boolean.FALSE.toString(), endTarget);
+            createAttribute("isTransient", Boolean.TRUE.toString(), endTarget);
+
             
         }
     }

Added: 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/FalseLookupCommand.java
URL: 
http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/FalseLookupCommand.java?rev=239992&view=auto
==============================================================================
--- 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/FalseLookupCommand.java
 (added)
+++ 
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/utils/FalseLookupCommand.java
 Wed Aug 24 21:44:52 2005
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * $Id$
+ */
+
+package org.apache.shale.clay.utils;
+
+import org.apache.commons.chain.Context;
+import org.apache.commons.chain.generic.LookupCommand;
+
+/**
+ * Very similar to the LookupCommand of commons chain, but the execute method
+ * return always false to continue the processing.
+ * @see org.apache.commons.chain.generic.LookupCommand
+ */
+public class FalseLookupCommand extends LookupCommand {
+    public boolean execute(Context context) throws Exception {
+        super.execute(context);
+        return false;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to