You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/10/17 20:54:37 UTC

svn commit: r705705 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/corelib/components/ main/java/org/apache/tapestry5/corelib/internal/ main/resources/org/apache/tapestry5/corelib/components/ test/app1/ test/java/org/a...

Author: hlship
Date: Fri Oct 17 11:54:37 2008
New Revision: 705705

URL: http://svn.apache.org/viewvc?rev=705705&view=rev
Log:
TAP5-281: Form should detect when it is nested inside another Form and identify that as an error

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/NestedForm.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/NestedForm.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Form.properties
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java Fri Oct 17 11:54:37 2008
@@ -214,14 +214,22 @@
         this.defaultTracker = defaultTracker;
     }
 
-    void beginRender(MarkupWriter writer)
+    void setupRender()
     {
+        FormSupport existing = environment.peek(FormSupport.class);
+
+        if (existing != null)
+            throw new TapestryException(messages.get("nesting-not-allowed"), existing, null);
+    }
 
+    void beginRender(MarkupWriter writer)
+    {
         actionSink = new ComponentActionSink(logger);
 
         name = renderSupport.allocateClientId(resources);
 
-        formSupport = new FormSupportImpl(name, actionSink, clientBehaviorSupport, clientValidation);
+        formSupport = new FormSupportImpl(resources.getLocation(), name, actionSink, clientBehaviorSupport,
+                                          clientValidation);
 
         if (zone != null) clientBehaviorSupport.linkZone(name, zone);
 
@@ -317,7 +325,7 @@
     {
         tracker.clear();
 
-        formSupport = new FormSupportImpl();
+        formSupport = new FormSupportImpl(resources.getLocation());
 
         environment.push(ValidationTracker.class, tracker);
         environment.push(FormSupport.class, formSupport);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/FormInjector.java Fri Oct 17 11:54:37 2008
@@ -214,7 +214,7 @@
 
                 reply.put("elementId", clientId);
 
-                FormSupportImpl formSupport = new FormSupportImpl(formId, actionSink, clientBehaviorSupport, true,
+                FormSupportImpl formSupport = new FormSupportImpl(null, formId, actionSink, clientBehaviorSupport, true,
                                                                   idAllocator);
 
                 environment.push(FormSupport.class, formSupport);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/FormSupportImpl.java Fri Oct 17 11:54:37 2008
@@ -17,6 +17,8 @@
 import org.apache.tapestry5.ComponentAction;
 import org.apache.tapestry5.Field;
 import org.apache.tapestry5.internal.services.ClientBehaviorSupport;
+import org.apache.tapestry5.ioc.BaseLocatable;
+import org.apache.tapestry5.ioc.Location;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.Defense;
 import org.apache.tapestry5.ioc.internal.util.IdAllocator;
@@ -30,7 +32,7 @@
  * <p/>
  * TODO: Most methods should only be invokable depending on whether the form is rendering or processing a submission.
  */
-public class FormSupportImpl implements FormSupport
+public class FormSupportImpl extends BaseLocatable implements FormSupport
 {
     private final ClientBehaviorSupport clientBehaviorSupport;
 
@@ -48,27 +50,33 @@
 
     /**
      * Constructor used when processing a form submission.
+     *
+     * @param location
      */
-    public FormSupportImpl()
+    public FormSupportImpl(Location location)
     {
-        this(null, null, null, false, null);
+        this(location, null, null, null, false);
     }
 
     /**
      * Constructor used when rendering.
      */
-    public FormSupportImpl(String clientId, ComponentActionSink actionSink, ClientBehaviorSupport clientBehaviorSupport,
+    public FormSupportImpl(Location location, String clientId, ComponentActionSink actionSink,
+                           ClientBehaviorSupport clientBehaviorSupport,
                            boolean clientValidationEnabled)
     {
-        this(clientId, actionSink, clientBehaviorSupport, clientValidationEnabled, new IdAllocator());
+        this(location, clientId, actionSink, clientBehaviorSupport, clientValidationEnabled, new IdAllocator());
     }
 
     /**
      * Full constructor.
      */
-    public FormSupportImpl(String clientId, ComponentActionSink actionSink, ClientBehaviorSupport clientBehaviorSupport,
+    public FormSupportImpl(Location location, String clientId, ComponentActionSink actionSink,
+                           ClientBehaviorSupport clientBehaviorSupport,
                            boolean clientValidationEnabled, IdAllocator idAllocator)
     {
+        super(location);
+
         this.clientId = clientId;
         this.actionSink = actionSink;
         this.clientBehaviorSupport = clientBehaviorSupport;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Form.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Form.properties?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Form.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/Form.properties Fri Oct 17 11:54:37 2008
@@ -13,3 +13,4 @@
 # limitations under the License.
 
 invalid-request=Forms require that the request method be POST and that the %s query parameter have values.
+nesting-not-allowed=Form components may not be placed inside other Form components.

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/NestedForm.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/NestedForm.tml?rev=705705&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/NestedForm.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/NestedForm.tml Fri Oct 17 11:54:37 2008
@@ -0,0 +1,8 @@
+<t:border xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <h1>Nested Form Demo</h1>
+
+    <t:form t:id="outer">
+        <t:form t:id="inner"/>
+    </t:form>
+
+</t:border>
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java Fri Oct 17 11:54:37 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -49,7 +49,7 @@
     {
         Request request = mockRequest();
         ComponentResources resources = mockComponentResources();
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         String elementName = "myname";
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/internal/FormSupportImplTest.java Fri Oct 17 11:54:37 2008
@@ -24,7 +24,7 @@
     @Test
     public void execute_deferred_with_no_commands()
     {
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         support.executeDeferred();
     }
@@ -42,7 +42,7 @@
 
         replay();
 
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         support.defer(r1);
         support.defer(r2);
@@ -66,7 +66,7 @@
 
         replay();
 
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         support.defer(r1);
         support.defer(r2);
@@ -89,7 +89,7 @@
     @Test
     public void set_encoding_type()
     {
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         String encodingType = "foo/bar";
 
@@ -101,7 +101,7 @@
     @Test
     public void set_encoding_type_to_same_value_is_allowed()
     {
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         String encodingType = "foo/bar";
 
@@ -115,7 +115,7 @@
     public void set_encoding_type_conflict()
     {
 
-        FormSupportImpl support = new FormSupportImpl();
+        FormSupportImpl support = new FormSupportImpl(null);
 
         support.setEncodingType("foo");
         try
@@ -128,7 +128,6 @@
             assertEquals(ex.getMessage(),
                          "Encoding type of form has already been set to \'foo\' and may not be changed to \'bar\'.");
         }
-
     }
 
     @Test
@@ -141,7 +140,7 @@
 
         replay();
 
-        FormSupportImpl support = new FormSupportImpl(null, null, clientBehaviorSupport, true);
+        FormSupportImpl support = new FormSupportImpl(null, null, null, clientBehaviorSupport, true);
 
         support.addValidation(barney, "required", "Who can live without Barney?", null);
 
@@ -156,12 +155,10 @@
 
         replay();
 
-        FormSupportImpl support = new FormSupportImpl(null, null, clientBehaviorSupport, false);
+        FormSupportImpl support = new FormSupportImpl(null, null, null, clientBehaviorSupport, false);
 
         support.addValidation(barney, "required", "Who can live without Barney?", null);
 
         verify();
     }
-
-
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java Fri Oct 17 11:54:37 2008
@@ -2348,4 +2348,14 @@
         assertTextPresent(
                 "Request event 'action' (on component UnhandledEventDemo:traditional) was not handled; you must provide a matching event handler method in the component or in one of its containers.");
     }
+
+    /**
+     * TAP5-281
+     */
+    public void nested_form_check()
+    {
+        start("Nested Form Demo");
+
+        assertTextPresent("Form components may not be placed inside other Form components.");
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/NestedForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/NestedForm.java?rev=705705&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/NestedForm.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/NestedForm.java Fri Oct 17 11:54:37 2008
@@ -0,0 +1,19 @@
+//  Copyright 2008 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.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+public class NestedForm
+{
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java?rev=705705&r1=705704&r2=705705&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java Fri Oct 17 11:54:37 2008
@@ -65,6 +65,8 @@
 
     private static final List<Item> ITEMS = CollectionFactory.newList(
 
+            new Item("NestedForm", "Nested Form Demo", "Error when a Form is nested inside another Form."),
+
             new Item("UnhandledEventDemo", "Unhandled Event Demo",
                      "Events that don't have matching event handlers cause exceptions"),