Moved preallocateReservedIds to RequestCycle implementation and removed from FormSupportImpl as it becomes redunant and unneccessary to do it for each form rendered.  (and really belongs in RequestCycle now anyways since it is the solve manager of IdAllocator now )

git-svn-id: https://svn.apache.org/repos/asf/tapestry/tapestry4/branches/MultipleFormIDGeneration@611908 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tapestry-framework/src/java/org/apache/tapestry/engine/RequestCycle.java b/tapestry-framework/src/java/org/apache/tapestry/engine/RequestCycle.java
index 4bc9e81..57cc03b 100644
--- a/tapestry-framework/src/java/org/apache/tapestry/engine/RequestCycle.java
+++ b/tapestry-framework/src/java/org/apache/tapestry/engine/RequestCycle.java
@@ -28,6 +28,7 @@
 import org.apache.tapestry.services.AbsoluteURLBuilder;
 import org.apache.tapestry.services.Infrastructure;
 import org.apache.tapestry.services.ResponseBuilder;
+import org.apache.tapestry.services.ServiceConstants;
 import org.apache.tapestry.util.IdAllocator;
 import org.apache.tapestry.util.QueryParameterMap;
 import org.apache.tapestry.util.io.CompressedDataEncoder;
@@ -392,9 +393,10 @@
     public void renderPage(ResponseBuilder builder)
     {
         _rewinding = false;
-
+        preallocateReservedIds();
+        
         try
-        {            
+        {
             _page.renderPage(builder, this);
 
         }
@@ -419,6 +421,19 @@
     }
 
     /**
+     * Pre allocates all {@link ServiceConstants#RESERVED_IDS} so that none
+     * are used as component or hidden ids as they would conflict with service
+     * parameters.
+     */
+    private void preallocateReservedIds()
+    {
+        for (int i = 0; i < ServiceConstants.RESERVED_IDS.length; i++)
+        {
+            _idAllocator.allocateId(ServiceConstants.RESERVED_IDS[i]);
+        }
+    }
+
+    /**
      * Resets all internal state after a render or a rewind.
      */
 
@@ -666,5 +681,6 @@
     public void initializeIdState(String encodedSeed)
     {
         _idAllocator = IdAllocator.fromExternalString( CompressedDataEncoder.decodeString(encodedSeed));
+        preallocateReservedIds();
     }
 }
diff --git a/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java b/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
index 5b0384b..839b1c5 100644
--- a/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
+++ b/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
@@ -253,13 +253,6 @@
         String sep = "";
         boolean hasExtra = false;
 
-        // All the reserved ids, which are essential for
-        // dispatching the request, are automatically reserved.
-        // Thus, if you have a component with an id of 'service', its element id
-        // will likely be 'service$0'.
-
-        preallocateReservedIds();
-
         for (int i = 0; i < count; i++)
         {
             String name = names[i];
@@ -398,7 +391,7 @@
 
         String filteredId = TapestryUtils.convertTapestryIdToNMToken(baseId);
 
-        String result = _cycle.getUniqueId(filteredId); //_elementIdAllocator.allocateId(filteredId);
+        String result = _cycle.getUniqueId(filteredId);
 
         if (_rewinding)
         {
@@ -440,22 +433,14 @@
         if (wasPrerendered(comp))
             return comp.getClientId();
 
-        return _cycle.peekUniqueId(id); //_elementIdAllocator.peekNextId(id);
+        return _cycle.peekUniqueId(id);
     }
 
     public boolean isRewinding()
     {
         return _rewinding;
     }
-
-    private void preallocateReservedIds()
-    {
-        for (int i = 0; i < ServiceConstants.RESERVED_IDS.length; i++)
-        {
-            _cycle.getUniqueId(ServiceConstants.RESERVED_IDS[i]);
-        }
-    }
-
+    
     /**
      * Invoked when rewinding a form to re-initialize the _allocatedIds and _elementIdAllocator.
      * Converts a string passed as a parameter (and containing a comma separated list of ids) back
@@ -480,8 +465,6 @@
         // Now, reconstruct the initial state of the
         // id allocator.
 
-        preallocateReservedIds();
-
         String extraReservedIds = _cycle.getParameter(RESERVED_FORM_IDS);
 
         ids = TapestryUtils.split(extraReservedIds);
diff --git a/tapestry-framework/src/scripts/TestListEdit.xml b/tapestry-framework/src/scripts/TestListEdit.xml
index 08b3d4a..915b6f3 100644
--- a/tapestry-framework/src/scripts/TestListEdit.xml
+++ b/tapestry-framework/src/scripts/TestListEdit.xml
@@ -35,7 +35,7 @@
 <input type="hidden" (name="(.*?)" value="(.*?)") />
 ]]>
             <match>name="formids" value="e,inputColor,inputColor_0,inputColor_1"</match>
-            <match>name="seedids" value="BrO0ABXcYABYsU2hlbGwkMCxCb2R5JDAsZm9ybSQw"</match>
+            <match>name="seedids" value="BrO0ABXdQAE4sc2VydmljZSQwLHBhZ2UkMCxjb21wb25lbnQkMCxjb250YWluZXIkMCxzZXNzaW9uJDAsc3AkMCxTaGVsbCQwLEJvZHkkMCxmb3JtJDA="</match>
             <match>name="component" value="form"</match>
             <match>name="page" value="ListEdit"</match>
             <match>name="service" value="direct"</match>
@@ -146,7 +146,7 @@
 <input type="hidden" (name="(.*?)" value="(.*?)") />
 ]]>
             <match>name="formids" value="e"</match>
-            <match>name="seedids" value="BrO0ABXcnACUsU2hlbGwkMCxCb2R5JDAsTGlzdEVkaXRGb3JtJDAsRm9ybSQw"</match>
+            <match>name="seedids" value="BrO0ABXdfAF0sc2VydmljZSQwLHBhZ2UkMCxjb21wb25lbnQkMCxjb250YWluZXIkMCxzZXNzaW9uJDAsc3AkMCxTaGVsbCQwLEJvZHkkMCxMaXN0RWRpdEZvcm0kMCxGb3JtJDA="</match>
             <match>name="component" value="$ListEditForm.$Form"</match>
             <match>name="page" value="ListEditArray"</match>
             <match>name="service" value="direct"</match>
@@ -175,7 +175,7 @@
 <input type="hidden" (name="(.*?)" value="(.*?)") />
 ]]>
             <match>name="formids" value="e"</match>
-            <match>name="seedids" value="BrO0ABXcnACUsU2hlbGwkMCxCb2R5JDAsTGlzdEVkaXRGb3JtJDAsRm9ybSQw"</match>
+            <match>name="seedids" value="BrO0ABXdfAF0sc2VydmljZSQwLHBhZ2UkMCxjb21wb25lbnQkMCxjb250YWluZXIkMCxzZXNzaW9uJDAsc3AkMCxTaGVsbCQwLEJvZHkkMCxMaXN0RWRpdEZvcm0kMCxGb3JtJDA="</match>
             <match>name="component" value="$ListEditForm.$Form"</match>
             <match>name="page" value="ListEditNull"</match>
             <match>name="service" value="direct"</match>
diff --git a/tapestry-framework/src/scripts/TestSelectOption.xml b/tapestry-framework/src/scripts/TestSelectOption.xml
index 5d2edba..d9c4535 100644
--- a/tapestry-framework/src/scripts/TestSelectOption.xml
+++ b/tapestry-framework/src/scripts/TestSelectOption.xml
@@ -39,7 +39,7 @@
 <input type="hidden" (name="(.*?)" value="(.*?)") />
 ]]>
             <match>name="formids" value="Select"</match>
-            <match>name="seedids" value="BrO0ABXcYABYsU2hlbGwkMCxCb2R5JDAsRm9ybSQw"</match>
+            <match>name="seedids" value="BrO0ABXdQAE4sc2VydmljZSQwLHBhZ2UkMCxjb21wb25lbnQkMCxjb250YWluZXIkMCxzZXNzaW9uJDAsc3AkMCxTaGVsbCQwLEJvZHkkMCxGb3JtJDA="</match>
             <match>name="component" value="$Form"</match>
             <match>name="page" value="Home"</match>
             <match>name="service" value="direct"</match>
@@ -129,7 +129,7 @@
 <input type="hidden" (name="(.*?)" value="(.*?)") />
 ]]>
             <match>name="formids" value="Select"</match>
-            <match>name="seedids" value="BrO0ABXcYABYsU2hlbGwkMCxCb2R5JDAsRm9ybSQw"</match>
+            <match>name="seedids" value="BrO0ABXdQAE4sc2VydmljZSQwLHBhZ2UkMCxjb21wb25lbnQkMCxjb250YWluZXIkMCxzZXNzaW9uJDAsc3AkMCxTaGVsbCQwLEJvZHkkMCxGb3JtJDA="</match>
             <match>name="component" value="$Form"</match>
             <match>name="page" value="Two"</match>
             <match>name="service" value="direct"</match>
@@ -229,7 +229,7 @@
             <!-- Remember the persistent properties?  Those made the app go stateful. -->
 
             <match>name="formids" value="Select"</match>
-            <match>name="seedids" value="BrO0ABXcYABYsU2hlbGwkMCxCb2R5JDAsRm9ybSQw"</match>
+            <match>name="seedids" value="BrO0ABXdQAE4sc2VydmljZSQwLHBhZ2UkMCxjb21wb25lbnQkMCxjb250YWluZXIkMCxzZXNzaW9uJDAsc3AkMCxTaGVsbCQwLEJvZHkkMCxGb3JtJDA="</match>
             <match>name="component" value="$Form"</match>
             <match>name="page" value="Three"</match>
             <match>name="service" value="direct"</match>
diff --git a/tapestry-framework/src/scripts/TestWMLComponents.xml b/tapestry-framework/src/scripts/TestWMLComponents.xml
index a5b8232..aee8235 100644
--- a/tapestry-framework/src/scripts/TestWMLComponents.xml
+++ b/tapestry-framework/src/scripts/TestWMLComponents.xml
@@ -126,7 +126,7 @@
             ]]>
             <match>u,l</match>
             <match>0</match>
-            <match><![CDATA[ZH4sIAAAAAAAAAFvzloG1PIMhTcclX8VAJyc/HUSFZOamFgFpz9zE9FQgnZuYmQek/PNcy1LzSoCs4NSSssQiOCPeAMgs9cwrKAVJFqfmpCZDVBWVZSan+mTmZQN5IJMB1AU3oG4AAAA=]]></match>
+            <match><![CDATA[ZH4sIAAAAAAAAAFvzloG1fAHDPJ3i1KKyzORUFQOdgsR0EJWcn1uQn5eaVwJm55UkZualFgHZxanFxZn5eSBWAZBwyQcSOfnpICokMxesxDMXYkQuUA+Q8s9zLYOYE5xaUpZYBGfEGwCZpZ55BaUlYINzUpMhqsBO8cnMywbyQCYDAJ2KEjSmAAAA]]></match>
             <match>go</match>
             <match>Home</match>
             <match>direct</match>
diff --git a/tapestry-framework/src/scripts/TestWMLStaleSession.xml b/tapestry-framework/src/scripts/TestWMLStaleSession.xml
index 498168f..a2e2f87 100644
--- a/tapestry-framework/src/scripts/TestWMLStaleSession.xml
+++ b/tapestry-framework/src/scripts/TestWMLStaleSession.xml
@@ -66,7 +66,7 @@
             <postfield .*?value="(.*?)" />
             ]]>
             <match></match>
-            <match>BrO0ABXcoACYsRG8kMCxTdGFsZVNlc3Npb24kMCxkaXJlY3RMaW5rJDAsZ28kMA==</match>
+            <match>ZH4sIAAAAAAAAAFvzloG1PIEhTqc4tagsMzlVxUCnIDEdRCXn5xbk56XmlYDZeSWJmXmpRUB2cWpxcWZ+HohVACRc8oFEcEliTmowXCIlsyg1ucQnMy8byEkHKgAAGmRtGWYAAAA=</match>
             <match>go</match>
             <match>Stale</match>
             <match>direct</match>