tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r434589 - in /tapestry/tapestry4/trunk: tapestry-examples/Workbench/src/context/WEB-INF/ tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/ tapestry-framework/src/java/org/apache/tapestry/form/ tapestry-framework/src...
Date Fri, 25 Aug 2006 01:30:20 GMT
Author: jkuhnert
Date: Thu Aug 24 18:30:19 2006
New Revision: 434589

URL: http://svn.apache.org/viewvc?rev=434589&view=rev
Log:
Removed hacky creation of synthetic events, fixed LinkSubmit issues for all browsers. 

Modified:
    tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/Fields.page
    tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/Fields.java
    tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/FieldsResults.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Form.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/ImageSubmit.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.script
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form_compat.js
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form.js

Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/Fields.page
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/Fields.page?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/Fields.page (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/Fields.page Thu
Aug 24 18:30:19 2006
@@ -32,7 +32,7 @@
   
   <component id="inputEnabled" type="Checkbox">
     <binding name="value" value="clientValidationEnabled"/> 
-    <binding name="onchange" value="literal:tapestry.form.submit(this.form)"/>
+    <binding name="onClick" value="literal:tapestry.form.submit(this.form)"/>
   </component>
   
   <component id="showError" type="ShowError">

Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/Fields.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/Fields.java?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/Fields.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/Fields.java
Thu Aug 24 18:30:19 2006
@@ -56,7 +56,7 @@
     {
         return getResultsPage();
     }
-
+    
     public void doByLink()
     {
         getResultsPage().setByLink(true);

Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/FieldsResults.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/FieldsResults.java?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/FieldsResults.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/fields/FieldsResults.java
Thu Aug 24 18:30:19 2006
@@ -14,7 +14,9 @@
 
 package org.apache.tapestry.workbench.fields;
 
+import org.apache.tapestry.annotations.InjectState;
 import org.apache.tapestry.html.BasePage;
+import org.apache.tapestry.workbench.Visit;
 
 /**
  * @author Howard Lewis Ship
@@ -27,4 +29,7 @@
      */
 
     public abstract void setByLink(boolean byLink);
+    
+    @InjectState("session-data")
+    public abstract Visit getVisit();
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Form.java?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Form.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Form.java
Thu Aug 24 18:30:19 2006
@@ -210,6 +210,7 @@
         String baseName = constructFormNameForDirectService(cycle);
         
         _name = baseName + getResponse().getNamespace();
+        setClientId(_name);
         
         if (_renderInformalParameters == null)
             _renderInformalParameters = new RenderInformalParameters();

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/FormSupportImpl.java
Thu Aug 24 18:30:19 2006
@@ -502,7 +502,7 @@
         
         // For XHTML compatibility
         _writer.attribute("id", formId);
-
+        
         if (_encodingType != null)
             _writer.attribute("enctype", _encodingType);
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/ImageSubmit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/ImageSubmit.java?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/ImageSubmit.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/ImageSubmit.java
Thu Aug 24 18:30:19 2006
@@ -63,10 +63,10 @@
         writer.beginEmpty("input");
         writer.attribute("type", "image");
         writer.attribute("name", getName());
-
+        
         if (disabled)
             writer.attribute("disabled", "disabled");
-
+        
         // NN4 places a border unless you tell it otherwise.
         // IE ignores the border attribute and never shows a border.
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
Thu Aug 24 18:30:19 2006
@@ -50,7 +50,6 @@
     protected boolean isClicked(IRequestCycle cycle, String name)
     {
         String value = cycle.getParameter(FormConstants.SUBMIT_NAME_PARAMETER);
-
         return name.equals(value);
     }
 
@@ -74,11 +73,11 @@
             Map symbols = new HashMap();
             symbols.put("form", form);
             symbols.put("name", name);
-
+            
             getScript().execute(this, cycle, pageRenderSupport, symbols);
-
+            
             writer.begin("a");
-            writer.attribute("href", (String) symbols.get("href"));
+            writer.attribute("href", (String)symbols.get("href"));
             
             renderIdAttribute(writer, cycle);
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.script
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.script?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.script
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.script
Thu Aug 24 18:30:19 2006
@@ -18,13 +18,13 @@
 <!DOCTYPE script PUBLIC
 	"-//Apache Software Foundation//Tapestry Script Specification 3.0//EN"
 	"http://tapestry.apache.org/dtd/Script_3_0.dtd">
-<script>
+<script>
 
-<input-symbol key="name" class="java.lang.String" required="yes"/>
-<input-symbol key="form" class="org.apache.tapestry.IForm" required="yes"/>
-
-<let key="href">
-  javascript:tapestry.form.submit('${form.name}', '${name}');
-</let>
+<input-symbol key="name" required="yes" />
+<input-symbol key="form" required="yes" />
+
+<let key="href">
+javascript:tapestry.form.submit("${form.clientId}", "${name}");
+</let>
 
 </script>

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=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js Thu Aug 24 18:30:19
2006
@@ -2,6 +2,7 @@
 
 dojo.require("dojo.event");
 dojo.require("dojo.event.browser");
+dojo.require("dojo.dom");
 
 dojo.require("tapestry.core");
 
@@ -15,24 +16,6 @@
 	forms:{}, // registered form references
 	
 	/**
-	 * Generically displays a window alert for the 
-	 * given field when in error.
-	 * 
-	 * @param field The field element
-	 * @param message The message to display
-	 */
-	invalidField:function(field, message){
-		if (field.disabled) return;
-		
-    	window.alert(message);
-    	this.focusField(field);
-	},
-	
-	invalid_field:function(field, message){
-		tapestry.form.invalidField(field, message); 
-	},
-	
-	/**
 	 * If possible, brings keyboard input focus
 	 * to the specified field.
 	 * 
@@ -49,60 +32,6 @@
 	},
 	
 	/**
-	 * Trims whitespace from before/after field.
-	 * @param id The field(field id) of the field to trim
-	 * 			 whitespace input from.
-	 */
-	trimField:function(id){
-		if (arguments.length < 1) return;
-		
-		var elm=dojo.byId(id);
-		if (!elm) return;
-		if ( elm.type != "text" && elm.type != "textarea"
-			&& elm.type != "password" ) { return; }
-		
-		elm.value = elm.value.replace(/(^\s*|\s*$)/g, "");
-	},
-	
-	/**
-	 * Checks if the field specified has a non-null value
-	 * selected. This covers input fields/checkboxes/radio groups/etc..
-	 * 
-	 * @param field The field(field id) of the field to check for input.
-	 * @param message The message to be displayed if no value has been input/selected
-	 * 				  for the field.
-	 */
-	requireField:function(field, message){
-		if (arguments.length < 1) return;
-		
-		var elem=dojo.byId(field);
-		if (!elem) return;
-		
-		// Are textbox, textarea, or password fields blank.
-		if ( (elem.type == "text" || elem.type == "textarea" || elem.type == "password") 
-			&& /^\s*$/.test(elem.value) ) {
-			this.invalidField(elem, message);
-			return;
-		}
-		// Does drop-down box have option selected.
-		else if ( (elem.type == "select-one" || elem.type == "select-multiple") 
-				&& elem.selectedIndex == -1 ) {
-			this.invalidField(elem, message);
-		}
-		// Does radio button group (or check box group) have option checked.
-		else if ( elem instanceof Array )  {
-			var checked = false;
-			for (var j = 0; j < elem.length; j++) {
-				if (elem[j].checked) { checked = true; }
-			}
-			if ( !checked ) {	
-				this.invalidField(elem, message);
-				return;
-			}
-		}
-	},
-	
-	/**
 	 * Registers the form with the local <code>forms</code> property so 
 	 * that there is a central reference of all tapestry forms.
 	 * 
@@ -223,24 +152,24 @@
 	 * is submitted.
 	 */
 	onFormSubmit:function(evt){
-		if (!evt || dj_undef("target", evt)) {
+		if(!evt || dj_undef("target", evt)) {
 			dojo.raise("No valid form event found with argument: " + evt);
 			return;
 		}
 		
 		var id=evt.target.getAttribute("id");
 		if (!id) {
-			dojo.log.warn("Form had no id attribute.");
+			dojo.raise("Form had no id attribute.");
 			return;
 		}
+		form = dojo.byId(id);
 		
-		var form = dojo.byId(id);
 		if (!dj_undef("value", form.submitmode)
 			&& (form.submitmode.value == "cancel" || form.submitmode.value == "refresh"))
{
 			return;
 		}
 		
-		if (!tapestry.form.validation.validateForm(evt.target, this.forms[id])) {
+		if (!tapestry.form.validation.validateForm(form, this.forms[id])) {
 			dojo.event.browser.stopEvent(evt);
 		}
 	},
@@ -260,24 +189,28 @@
 			dojo.raise("Form not found with id " + form);
 			return;
 		}
+		var id=form.getAttribute("id");
 		
 		if (submitName){
 			form.submitname.value=submitName;
 		}
 		
-		// listeners trigerred then for some reason.
-		// try to create a real event so any listeners get notified
-		if (!dj_undef("createEvent", document)){
-			var ev = document.createEvent("HTMLEvents");
-			ev.initEvent("submit", true, true);
-			form.dispatchEvent(ev);
-		} else if (!dj_undef("createEventObject", document)) {
-			form.fireEvent("onsubmit");
-		} else {
-			dojo.log.warn("tapestry.form.submit using default form.submit() call, no event objects
found in browser.");
+		if (!dj_undef("value", form.submitmode)
+			&& (form.submitmode.value == "cancel" || form.submitmode.value == "refresh"))
{
 			form.submit();
 			return;
 		}
+		
+		if (!tapestry.form.validation.validateForm(form, this.forms[id])) {
+			return;
+		}
+		
+		if(!dj_undef(id, this.forms) && this.forms[id].async){
+			tapestry.form.submitAsync(form);
+			return;
+		}
+		
+		form.submit();
 	},
 	
 	cancel:function(form, submitName){

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js Thu Aug
24 18:30:19 2006
@@ -42,8 +42,8 @@
 	 * 			will ~not~ be submitted. 
 	 */
 	validateForm:function(form, props){
-		if (!form) return false;
-		if (!props) return true; // form exists but no profile? just submit I guess..
+		if (typeof form == "undefined") return false;
+		if (typeof props == "undefined") return true; // form exists but no profile? just submit
I guess..
 		if (!props.validateForm) return true;
 		
 		try {
@@ -140,7 +140,7 @@
 	 * in error.
 	 */
 	clearValidationDecorations:function(form, props){
-		for (var i=0; i<form.elements.length; i++) {
+		for (var i=0; i< form.elements.length; i++) {
 			if (typeof form.elements[i].type == "undefined"
 				|| form.elements[i].type == "submit" 
 				|| form.elements[i].type == "hidden") { continue; }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form_compat.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form_compat.js?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form_compat.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form_compat.js Thu Aug 24
18:30:19 2006
@@ -21,9 +21,16 @@
 
 Tapestry.default_invalid_field_handler=function(event, field, message){
 	dojo.deprecated("Tapestry.default_invalid_field_handler", 
-					"use tapestry.form.invalidField instead", 
+					"use tapestry.form.validation.validateForm instead", 
 					"4.1.1");
-	tapestry.form.invalidField(field, message);
+	if (field.disabled) return;
+    
+    if (typeof window != "undefined"){
+    	window.alert(message);
+    } else {
+    	dojo.debug("Invalid field : " + message);
+    }
+    tapestry.form.focusField(field);
 }
 
 Tapestry.find=function(id){
@@ -57,17 +64,51 @@
 Tapestry.trim_field_value = function(fieldId)
 {
 	dojo.deprecated("Tapestry.trim_field_value",
-					"use tapestry.form.trimField instead",
+					"use dojo.html instead",
 					"4.1.1");
-	tapestry.form.trimField(fieldId);
+	
+	if (arguments.length < 1) return;
+	
+	var elm=dojo.byId(id);
+	if (!elm) {return;}
+	if ( elm.type != "text" && elm.type != "textarea"
+		&& elm.type != "password" ) { return; }
+		
+	elm.value = elm.value.replace(/(^\s*|\s*$)/g, "");
 }
 
-Tapestry.require_field = function(event, fieldId, message)
+Tapestry.require_field = function(event, field, message)
 {
 	dojo.deprecated("Tapestry.require_field",
-					"use tapestry.form.requireField instead",
+					"use tapestry.form.validation.validateForm instead",
 					"4.1.1");
-	tapestry.form.requireField(fieldId, message);
+	if (arguments.length < 1) return;
+	
+	var elem=dojo.byId(field);
+	if (!elem) { return; }
+	
+	// Are textbox, textarea, or password fields blank.
+	if ( (elem.type == "text" || elem.type == "textarea" || elem.type == "password") 
+		&& /^\s*$/.test(elem.value) ) {
+		Tapestry.default_invalid_field_handler(elem, message);
+		return;
+	}
+	// Does drop-down box have option selected.
+	else if ( (elem.type == "select-one" || elem.type == "select-multiple") 
+			&& elem.selectedIndex == -1 ) {
+		Tapestry.default_invalid_field_handler(elem, message);
+		return;
+	} else if ( elem instanceof Array )  {
+		// Does radio button group (or check box group) have option checked.
+		var checked = false;
+		for (var j = 0; j < elem.length; j++) {
+			if (elem[j].checked) { checked = true; }
+		}
+		if ( !checked ) {	
+			Tapestry.default_invalid_field_handler(elem, message);
+			return;
+		}
+	}
 }
 
 Tapestry.submit_form = function(form_id, field_name)

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form.js?rev=434589&r1=434588&r2=434589&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tests/test_form.js Thu Aug 24 18:30:19
2006
@@ -41,7 +41,6 @@
 
 function test_form_invalidHandler(){
 	Tapestry.default_invalid_field_handler(null, "yo", "yo");
-	tapestry.form.invalidField("this", "field");
 }
 
 function test_form_requireTextField(){
@@ -53,12 +52,12 @@
 	node.value="";
 	
 	var mockInvalid=new mock(node, "must have value");
-	dojo.event.connect(tapestry.form, "invalidField", mockInvalid, "intercept");
+	dojo.event.connect(Tapestry, "default_invalid_field_handler", mockInvalid, "intercept");
 	
-	tapestry.form.requireField("testid", "must have value");
+	Tapestry.require_field(null, "testid", "must have value");
 	
 	jum.assertTrue("invalidCalled", mockInvalid.called);
-	dojo.event.disconnect(tapestry.form, "invalidField", mockInvalid, "intercept");
+	dojo.event.disconnect(Tapestry, "default_invalid_field_handler", mockInvalid, "intercept");
 }
 
 function test_form_submit(){
@@ -69,10 +68,8 @@
 	node.submit=function(){
 		submitCalled=true;
 	}
-	node.dispatchEvent=function(){
-		submitCalled=true;
-	}
 	node.submitname={value:""};
+	node.elements=[];
 	
 	Tapestry.register_form("form1");
 	Tapestry.submit_form("form1", "testSubmit");



Mime
View raw message