tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschu...@apache.org
Subject svn commit: r552217 - in /tapestry/tapestry4/trunk/tapestry-framework/src: descriptor/META-INF/tapestry.data.xml java/org/apache/tapestry/ComponentEvent.script java/org/apache/tapestry/util/io/JSONAdaptor.java js/tapestry/core.js
Date Sat, 30 Jun 2007 21:54:22 GMT
Author: mschulte
Date: Sat Jun 30 14:54:21 2007
New Revision: 552217

URL: http://svn.apache.org/viewvc?view=rev&rev=552217
Log:
Tentative fix for TAPESTRY-1202

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/io/JSONAdaptor.java
Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.data.xml
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/ComponentEvent.script
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.data.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.data.xml?view=diff&rev=552217&r1=552216&r2=552217
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.data.xml
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.data.xml
Sat Jun 30 14:54:21 2007
@@ -94,6 +94,7 @@
     <adaptor object="service:SerializableAdaptor"/>
     <adaptor object="instance:ShortAdaptor"/>
     <adaptor object="instance:StringAdaptor"/>
+    <adaptor object="instance:JSONAdaptor"/>
   </contribution>
 
 </module>

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?view=diff&rev=552217&r1=552216&r2=552217
==============================================================================
--- 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 Jun 30 14:54:21 2007
@@ -17,15 +17,25 @@
         <if expression="events">
             <foreach expression="events" key="event">
                 tapestry.cleanConnect(dojo.byId("${clientId}"), "${event[0]}", "event${event[1]}");
-                tapestry.event${event[1]}=function(e){
+                tapestry.event${event[1]}=function( inv ){
+                    result = inv.proceed();
+                    
                     var content={beventname:"${event[0]}"};
-                    tapestry.event.buildEventProperties(e, content);
+                    var event = inv.args[0];
+                    tapestry.event.buildEventProperties( event, content);               
    
                     if (!content["beventtarget.id"]) {
                     	content["beventtarget.id"]="${clientId}";
                     }
+                    
+                    if (! dojo.event.browser.isEvent(event)){
+                    	tapestry.event.buildMethodInterceptionProperties( inv.args, content
);
+                    }
+                    
                     tapestry.bind("${url}", content);
+
+                    return result;
                 };
-                dojo.event.connect(dojo.byId("${clientId}"), "${event[0]}", tapestry, "event${event[1]}");
+                dojo.event.connect("around", dojo.byId("${clientId}"), "${event[0]}", tapestry,
"event${event[1]}");
             </foreach>
         </if>
         <if expression="formEvents">

Added: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/io/JSONAdaptor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/io/JSONAdaptor.java?view=auto&rev=552217
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/io/JSONAdaptor.java
(added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/io/JSONAdaptor.java
Sat Jun 30 14:54:21 2007
@@ -0,0 +1,63 @@
+// Copyright 2004, 2005 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.tapestry.util.io;
+
+import java.text.ParseException;
+
+import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.tapestry.json.JSONObject;
+import org.apache.tapestry.services.DataSqueezer;
+
+/**
+ * Squeezes a JSONObject
+ */
+
+public class JSONAdaptor implements SqueezeAdaptor
+{
+
+    private static final String PREFIX = "J";
+
+    public String getPrefix()
+    {
+        return PREFIX;
+    }
+
+    public Class getDataClass()
+    {
+        return JSONObject.class;
+    }
+
+    public String squeeze(DataSqueezer squeezer, Object data)
+    {
+        JSONObject o = (JSONObject) data;
+
+        return PREFIX + o.toString();
+    }
+
+    /**
+     * Build a JSONObject from the String
+     */
+
+    public Object unsqueeze(DataSqueezer squeezer, String string)
+    {
+        if (string.length() == 1) return "";
+
+        try {
+            return new JSONObject(string.substring(1));
+        } catch (ParseException ex) {
+            throw new ApplicationRuntimeException(ex);
+        }
+    }
+}

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js?view=diff&rev=552217&r1=552216&r2=552217
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js Sat Jun 30 14:54:21
2007
@@ -7,6 +7,7 @@
 dojo.require("dojo.io.BrowserIO");
 dojo.require("dojo.event.browser");
 dojo.require("dojo.html.style");
+dojo.require("dojo.json");
 
 // redirect logging calls to standard debug if logging not enabled
 if (dj_undef("logging", dojo)) {
@@ -604,8 +605,8 @@
 	 * The desired event properties bound to an object. Ie obj.target,obj.charCode, etc..
 	 */
 	buildEventProperties:function(event, props){
-		if (!dojo.event.browser.isEvent(event)) return {};
 		if (!props) props={};
+		if (!dojo.event.browser.isEvent(event)) return props;
 
 		if(event["type"]) props.beventtype=event.type;
 		if(event["keys"]) props.beventkeys=event.keys;
@@ -617,6 +618,39 @@
 
 		if (event["target"]) this.buildTargetProperties(props, event.target);
 
+		return props;
+	},
+	
+	
+	/**
+	 * Function: buildMethodInterceptionProperties
+	 *
+	 * Stuffs the parameters of an @EventListener-intercepted method into
+	 * a property object suitable to be passed as the content-argument to 
+	 * the bind-function. Arguments will be passed as service-parameters (sp)
+	 * so that the usual listener-invocation mechanism can do its work. 
+	 * String parameters are encoded as such (StringAdaptor, prefix "S")
+	 * Other types/objects will be serialised to a JSON-String which is
+	 * to be handled by the JSONAdaptor on the server side (prefix "J").  
+	 *
+	 * Parameters:
+	 *
+	 *	args - the arguments array.
+	 *	props - The existing property object to set the values on, if it doesn't
+	 * 				exist one will be created.
+	 * Returns:
+	 *
+	 * The passed in properties object augmented in the way described above
+	 */
+	buildMethodInterceptionProperties:function( args, props ){
+	    if (!props) props={};
+	    props.sp = new Array();
+		for ( var i=0; i < args.length; i++ ) {
+			if ( typeof(args[i]) == "string" )
+				props.sp[i] = "S"+String(args[i]);
+			else
+				props.sp[i] = "J"+dojo.json.serialize( args[i] );	
+		}
 		return props;
 	},
 



Mime
View raw message