You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2006/08/05 20:28:54 UTC

svn commit: r429026 - in /tapestry/tapestry4/trunk: src/site/apt/javascript/ tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/ tapestry-framework/src/java/org/apache/tapestry/ tapestry-framework/src/java/org/apache/tapestry/d...

Author: jkuhnert
Date: Sat Aug  5 11:28:53 2006
New Revision: 429026

URL: http://svn.apache.org/viewvc?rev=429026&view=rev
Log:
EventListener(validateForm=true/false) parameter wasn't actually being used. Refactored to make use of it.

Modified:
    tapestry/tapestry4/trunk/src/site/apt/javascript/form.apt
    tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/ComponentEvent.script
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/WidgetEvent.script
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/ElementEvent.script
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java

Modified: tapestry/tapestry4/trunk/src/site/apt/javascript/form.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/src/site/apt/javascript/form.apt?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/src/site/apt/javascript/form.apt (original)
+++ tapestry/tapestry4/trunk/src/site/apt/javascript/form.apt Sat Aug  5 11:28:53 2006
@@ -222,7 +222,7 @@
   form 				   | String element id / HTMLForm node |  yes  |          | The element id of the form, or the form html element itself.
 *----------------------*---------------*------------*----------*----------------------------------------------+
 
-* tapestry.form.submitAsync(form, content, submitName)
+* tapestry.form.submitAsync(form, content, submitName, validate)
 
   Similar to the {{{core.html}tapestry.bind}} function call, in that it submits the request asynchronously and
   expects a valid tapestry xml content response. This is the core function used by Tapestry when submitting
@@ -236,4 +236,6 @@
   content 			   | json          |  no        |          | A properties map of optional extra content to send. This will be sent <in addition> to the content encapsulated by your form. 
 *----------------------*---------------*------------*----------*----------------------------------------------+
   submitName 		   | String        |  no        |          | Optional submit name string to use when submitting to bind the request to a specific {{{../components/Submit.html}Submit}} component.
+*----------------------*---------------*------------*----------*----------------------------------------------+
+  validate 		       | boolean       |  no        |   false  | Controls whether or not to invoke client side validation.
 *----------------------*---------------*------------*----------*----------------------------------------------+

Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/java/org/apache/tapestry/timetracker/page/TaskEntryPage.java Sat Aug  5 11:28:53 2006
@@ -100,7 +100,7 @@
      * selection list.
      */
     @EventListener(events = "selectOption", targets = "projectChoose",
-            submitForm = "taskForm", async=true)
+            submitForm = "taskForm", validateForm = true)
     public void projectSelected(IRequestCycle cycle)
     {
         cycle.getResponseBuilder().updateComponent("projectDescription");

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/ComponentEvent.script
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/ComponentEvent.script?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/ComponentEvent.script (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/ComponentEvent.script Sat Aug  5 11:28:53 2006
@@ -34,12 +34,20 @@
                     if (!content["beventtarget.id"]) content["beventtarget.id"]="${clientId}";
                     
                     <foreach expression="formEvent[1]" key="formName">
+                   var validateState=tapestry.form.forms["${formName}"].validateForm;
+                   var validateForm=${formEvent[3]};
+                   tapestry.form.setFormValidating("${formname}", validateForm);
+                   
                     <if expression="formEvent[2]">
-                    tapestry.form.submitAsync("${formName}", content);
+                    tapestry.form.submitAsync("${formName}", content, null, validateForm);
                     </if>
                     <if-not expression="formEvent[2]">
                     tapestry.form.submit("${formName}");
                     </if-not>
+                    
+                    if (!dj_undef("validateState", this)) { 
+                        tapestry.form.setFormValidating("${formName}", validateState);
+                    }
                     </foreach>
                 });
             </foreach>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/WidgetEvent.script
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/WidgetEvent.script?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/WidgetEvent.script (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/WidgetEvent.script Sat Aug  5 11:28:53 2006
@@ -34,12 +34,20 @@
                     if (!content["beventtarget.id"]) content["beventtarget.id"]="${clientId}";
                     
                    <foreach expression="formEvent[1]" key="formName">
+                   var validateState=tapestry.form.forms["${formName}"].validateForm;
+                   var validateForm=${formEvent[3]};
+                   tapestry.form.setFormValidating("${formname}", validateForm);
+                   
                     <if expression="formEvent[2]">
-                    tapestry.form.submitAsync("${formName}", content);
+                    tapestry.form.submitAsync("${formName}", content, null, validateForm);
                     </if>
                     <if-not expression="formEvent[2]">
                     tapestry.form.submit("${formName}");
                     </if-not>
+                    
+                    if (!dj_undef("validateState", this)) { 
+                        tapestry.form.setFormValidating("${formName}", validateState);
+                    }
                     </foreach>
                 });
             </foreach>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc Sat Aug  5 11:28:53 2006
@@ -32,6 +32,7 @@
       value supplied in the query parameter on form submit).
     </description>
   </parameter>
+  
   <parameter name="disabled">
       <description>
           If true, then the component is disabled, which will be reflected in the
@@ -39,22 +40,26 @@
           during the form submission.
       </description>
   </parameter>
+  
   <parameter name="selected">
       <description>
           If bound, then this parameter will be updated with the value of the
           tag parameter, if the Submit is triggered.
        </description>
   </parameter>
+  
   <parameter name="tag">
       <description>
           A tag value used to identify this Submit as the triggered component.
       </description>
   </parameter>
+  
   <parameter name="listener">
       <description>
           A listener that is notified if this component is triggered.
       </description>
   </parameter>
+  
   <parameter name="action">
       <description>
           A listener that is notified if this component is triggered
@@ -62,6 +67,7 @@
           enclosed by the Form have had a chance to update their properties.
       </description>
   </parameter>
+  
   <parameter name="parameters">
     <description>
     An object, or list of objects, gathered when the button is triggered and 
@@ -69,6 +75,7 @@
     the parameters available to a deferred listener.
     </description>
   </parameter>
+  
   <parameter name="id" property="idParameter" default-value="id"/>
   		  
   <reserved-parameter name="name"/>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/ElementEvent.script
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/ElementEvent.script?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/ElementEvent.script (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/ElementEvent.script Sat Aug  5 11:28:53 2006
@@ -33,7 +33,20 @@
                     if (!content["beventtarget.id"]) content["beventtarget.id"]="${target}";
                     
                     <foreach expression="formEvent[1]" key="formName">
-                    tapestry.form.submitAsync("${formName}", content);
+                   var validateState=tapestry.form.forms["${formName}"].validateForm;
+                   var validateForm=${formEvent[3]};
+                   tapestry.form.setFormValidating("${formname}", validateForm);
+                   
+                    <if expression="formEvent[2]">
+                    tapestry.form.submitAsync("${formName}", content, null, validateForm);
+                    </if>
+                    <if-not expression="formEvent[2]">
+                    tapestry.form.submit("${formName}");
+                    </if-not>
+                    
+                    if (!dj_undef("validateState", this)) { 
+                        tapestry.form.setFormValidating("${formName}", validateState);
+                    }
                     </foreach>
                 });
             </foreach>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentEventConnectionWorker.java Sat Aug  5 11:28:53 2006
@@ -60,10 +60,16 @@
     // handles resolving and loading different component event 
     // connection script types
     private IScriptSource _scriptSource;
+    
+    // script path references
     private String _componentScript;
     private String _widgetScript;
     private String _elementScript;
+    
+    // resolves classpath relative resources
     private ClassResolver _resolver;
+    
+    // wrappers around resolved script templates
     private ClasspathResource _componentResource;
     private ClasspathResource _widgetResource;
     private ClasspathResource _elementResource;
@@ -188,8 +194,9 @@
             IComponent component = (IComponent)scriptParms.get("component");
             
             ComponentEventProperty props = _invoker.getComponentEvents(component.getId());
+            
             Object[][] formEvents = buildFormEvents(cycle, form.getId(), 
-                    props.getFormEvents(), (Boolean)val[1]);
+                    props.getFormEvents(), (Boolean)val[1], (Boolean)val[2]);
             
             // don't want any events accidently connected again
             scriptParms.remove("events");
@@ -203,7 +210,8 @@
         }
     }
     
-    Object[][] buildFormEvents(IRequestCycle cycle, String formId, Set events, Boolean async)
+    Object[][] buildFormEvents(IRequestCycle cycle, String formId, 
+            Set events, Boolean async, Boolean validate)
     {
         List formNames = (List)cycle.getAttribute(FORM_NAME_LIST + formId);
         List retval = new ArrayList();
@@ -213,11 +221,11 @@
         while (it.hasNext()) {
             
             String event = (String)it.next();
-            retval.add(new Object[]{event, formNames, async});
+            retval.add(new Object[]{event, formNames, async, validate});
             
         }
         
-        return (Object[][])retval.toArray(new Object[retval.size()][3]);
+        return (Object[][])retval.toArray(new Object[retval.size()][4]);
     }
     
     Resource getScript(IComponent component)
@@ -288,16 +296,21 @@
                 // defer connection until form is rendered
                 if (formNames == null) {
                     
-                    deferFormConnection(formId, scriptParms, listener.isAsync());
+                    deferFormConnection(formId, scriptParms, 
+                            listener.isAsync(), listener.isValidateForm());
                     continue;
                 }
                 
                 // form has been rendered so go ahead
-                retval.add(new Object[] {event, formNames, Boolean.valueOf(listener.isAsync())});
+                retval.add(new Object[] {
+                        event, formNames, 
+                        Boolean.valueOf(listener.isAsync()), 
+                        Boolean.valueOf(listener.isValidateForm())
+                });
             }
         }
         
-        return (Object[][])retval.toArray(new Object[retval.size()][3]);
+        return (Object[][])retval.toArray(new Object[retval.size()][4]);
     }
     
     /**
@@ -312,11 +325,12 @@
      * deferred list.
      * </p>
      * 
-     * @param formId
-     * @param scriptParms
-     * @param async
+     * @param formId The form to defer event connection for.
+     * @param scriptParms The initial map of parameters for the connection @Script component.
+     * @param async Whether or not the action taken should be asynchronous.
+     * @param validate Whether or not the form should have client side validation run befor submitting.
      */
-    void deferFormConnection(String formId, Map scriptParms, boolean async)
+    void deferFormConnection(String formId, Map scriptParms, boolean async, boolean validate)
     {
         List deferred = (List)_deferredFormConnections.get(formId);
         
@@ -326,7 +340,7 @@
             _deferredFormConnections.put(formId, deferred);
         }
         
-        deferred.add(new Object[] {scriptParms, Boolean.valueOf(async)});
+        deferred.add(new Object[] {scriptParms, Boolean.valueOf(async), Boolean.valueOf(validate)});
     }
     
     // for testing

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js Sat Aug  5 11:28:53 2006
@@ -126,7 +126,7 @@
 			
 			dojo.event.connect(form, "onsubmit", this, "onFormSubmit");
 		} else {
-			dojo.log.warn("registerForm(" + id + ") Form already registered.");
+			dojo.log.warn("egisterForm(" + id + ") Form already registered.");
 		}
 	},
 	
@@ -265,11 +265,18 @@
 	 * 				  event parameters to form submission, but can be any
 	 * 				  typical form/value pair.
 	 * @param submitName Optional submit name string to use when submitting.
+	 * @param validate Whether or not to validate form, default is false.
 	 */
-	submitAsync:function(form, content, submitName){
+	submitAsync:function(form, content, submitName, validate){
 		var form=dojo.byId(form);
 		if (!form) {
 			dojo.raise("Form not found with id " + id);
+			return;
+		}
+		var formId=form.getAttribute("id");
+		
+		if (validate && !tapestry.form.validation.validateForm(form, this.forms[formId])) {
+			dojo.log.debug("Form validation failed for form with id " + formId);
 			return;
 		}
 		

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java?rev=429026&r1=429025&r2=429026&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/ComponentEventConnectionWorkerTest.java Sat Aug  5 11:28:53 2006
@@ -19,7 +19,6 @@
 import static org.easymock.EasyMock.isA;
 import static org.testng.AssertJUnit.assertEquals;
 import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertNull;
 import static org.testng.AssertJUnit.assertTrue;
 
 import java.util.ArrayList;
@@ -56,7 +55,7 @@
 public class ComponentEventConnectionWorkerTest extends BaseComponentTestCase
 {
 
-    public void testEventRenderChain()
+    public void test_Event_Render_Chain()
     {   
         ClassResolver resolver = new DefaultClassResolver();
         
@@ -155,7 +154,7 @@
         verify();
     }
     
-    public void testRewindRender()
+    public void test_Rewind_Render()
     {
         IRequestCycle cycle = newCycle();
         
@@ -170,7 +169,7 @@
         verify();
     }
     
-    public void testNullPageSupport()
+    public void test_Null_PageSupport()
     {
         IRequestCycle cycle = newCycle();
         
@@ -187,7 +186,7 @@
         verify();
     }
     
-    public void testDeferredConnection()
+    public void test_Deferred_Connection()
     {
         ComponentEventInvoker invoker = new ComponentEventInvoker();
         IEngineService engine = newMock(IEngineService.class);
@@ -202,7 +201,7 @@
         
         // now test render
         invoker.addEventListener("comp1", new String[] {"onclick"}, 
-                "testMethod", "form1", false, false);
+                "testMethod", "form1", true, false);
         
         expect(cycle.isRewinding()).andReturn(false);
         
@@ -224,27 +223,32 @@
         assertEquals(1, worker.getDefferedFormConnections().size());
         
         List deferred = (List)worker.getDefferedFormConnections().get("form1");
-        assertNotNull(deferred);
+        
+        assert deferred != null;
         assertEquals(1, deferred.size());
         
         Object[] parms = (Object[])deferred.get(0);
-        assertEquals(2, parms.length);
-        Map parm = (Map)parms[0];
+        assertEquals(3, parms.length);
         
-        Boolean async = (Boolean)parms[1];
-        assertTrue(!async.booleanValue());
+        // assert async is false
+        assert (Boolean)parms[1] == false;
+        
+        // assert validate form is true
+        assert (Boolean)parms[2] == true;
+        
+        Map parm = (Map)parms[0];
         
-        assertNotNull(parm.get("clientId"));
-        assertNotNull(parm.get("component"));
-        assertNull(parm.get("url"));
-        assertNull(parm.get("formEvents"));
-        assertNull(parm.get("target"));
+        assert parm.get("clientId") != null;
+        assert parm.get("component") != null;
+        assert parm.get("url") == null;
+        assert parm.get("formEvents") == null;
+        assert parm.get("target") == null;
         
         assertEquals("comp1", parm.get("clientId"));
         assertEquals(component, parm.get("component"));
     }
     
-    public void testFormRenderDeffered()
+    public void test_Form_Render_Deffered()
     {
         ClassResolver resolver = new DefaultClassResolver();
         
@@ -332,7 +336,7 @@
         verify();
     }
     
-    public void testScriptResource()
+    public void test_Script_Resource()
     {   
         ClassResolver resolver = new DefaultClassResolver();
         ComponentEventInvoker invoker = new ComponentEventInvoker();
@@ -367,7 +371,7 @@
         verify();
     }
     
-    public void testPrerenderedField()
+    public void test_Prerendered_Field()
     {   
         ClassResolver resolver = new DefaultClassResolver();