Author: kmenard
Date: Fri Sep 26 12:28:35 2008
New Revision: 699459

URL: http://svn.apache.org/viewvc?rev=699459&view=rev
Log:
Fixed TAP5-197: Improved error message when using a form component outside of a 
form.

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldOutsideForm.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldOutsideForm.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalMessages.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/internal/InternalStrings.properties
    
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/base/AbstractField.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java?rev=699459&r1=699458&r2=699459&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractField.java
 Fri Sep 26 12:28:35 2008
@@ -19,6 +19,7 @@
 import org.apache.tapestry5.corelib.mixins.DiscardBody;
 import org.apache.tapestry5.corelib.mixins.RenderDisabled;
 import org.apache.tapestry5.corelib.mixins.RenderInformals;
+import org.apache.tapestry5.corelib.internal.InternalMessages;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.services.ComponentDefaultProvider;
 import org.apache.tapestry5.services.FormSupport;
@@ -111,7 +112,7 @@
 
     private String controlName;
 
-    @Environmental
+    @Environmental(false)
     private FormSupport formSupport;
 
     @Environmental
@@ -145,6 +146,8 @@
         // exceptions, including a form that renders inside a loop, or a form 
inside a component
         // that is used multiple times.
 
+        if (formSupport == null) throw new 
RuntimeException(InternalMessages.formFieldOutsideForm(getLabel()));
+
         assignedClientId = renderSupport.allocateClientId(id);
         String controlName = formSupport.allocateControlName(id);
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalMessages.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalMessages.java?rev=699459&r1=699458&r2=699459&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalMessages.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/internal/InternalMessages.java
 Fri Sep 26 12:28:35 2008
@@ -47,4 +47,9 @@
     {
         return MESSAGES.format("to-client-should-return-string");
     }
+
+    public static String formFieldOutsideForm(String fieldName)
+    {
+        return MESSAGES.format("form-field-outside-form", fieldName);
+    }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/internal/InternalStrings.properties
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/internal/InternalStrings.properties?rev=699459&r1=699458&r2=699459&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/internal/InternalStrings.properties
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/internal/InternalStrings.properties
 Fri Sep 26 12:28:35 2008
@@ -17,3 +17,4 @@
 failure-instantitating-object=Exception instantiating instance of %s (for 
component '%s'): %s
 conflicting-encoding-type=Encoding type of form has already been set to '%s' 
and may not be changed to '%s'.
 to-client-should-return-string=Return value from 'parseClient' event handler 
method must be a string.
+form-field-outside-form=The %s component must be enclosed by a Form component.
\ No newline at end of file

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldOutsideForm.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldOutsideForm.tml?rev=699459&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldOutsideForm.tml 
(added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormFieldOutsideForm.tml 
Fri Sep 26 12:28:35 2008
@@ -0,0 +1,7 @@
+<html t:type="Border" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
+
+    <h1>Form Field Outside Form</h1>
+
+    <t:textfield value="quantity" size="3"/>
+
+</html>

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=699459&r1=699458&r2=699459&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 Sep 26 12:28:35 2008
@@ -2280,4 +2280,13 @@
 
         assertText("event", "failure");
     }
+
+    public void form_field_outside_form()
+    {
+        start("Form Field Outside Form");
+
+        
assertTextPresent("org.apache.tapestry5.internal.services.RenderQueueException",
+                          "Render queue error in 
SetupRender[FormFieldOutsideForm:textfield]: The Textfield component must be 
enclosed by a Form component.",
+                          "context:FormFieldOutsideForm.tml, line 5, column 
45");
+    }
 }

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldOutsideForm.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldOutsideForm.java?rev=699459&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldOutsideForm.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormFieldOutsideForm.java
 Fri Sep 26 12:28:35 2008
@@ -0,0 +1,23 @@
+// 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;
+
+import org.apache.tapestry5.annotations.Property;
+
+public class FormFieldOutsideForm
+{
+    @Property
+    private int quantity;
+}

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=699459&r1=699458&r2=699459&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 Sep 26 12:28:35 2008
@@ -287,7 +287,9 @@
                      "BeanEditContext is pushed into enviroment by 
BeanEditor."),
 
             new Item("InformalParametersDemo", "Informal Parameters Demo",
-                     "Access to informal parameters names and values")
+                     "Access to informal parameters names and values"),
+
+            new Item("FormFieldOutsideForm", "Form Field Outside Form", "Nice 
exception message for common problem of form fields outside forms")
     );
 
     static


Reply via email to