You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ms...@apache.org on 2007/06/30 23:54:22 UTC
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
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;
},
Re: 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
Posted by Marcus Schulte <et...@googlemail.com>.
Thanks Jesse, that was really just an initial commit to see whether you
really dislike the approach. And I think, I got your point now. I have
really no problem with that.
2007/7/1, Jesse Kuhnert <jk...@gmail.com>:
>
> Sorry it took so long to respond. I've looked things over and have some
> thoughts on the changes.
>
> -) Where are the unit tests? :) I don't always do this properly and
> there
> are certainly cases where a feature is covered by integration tests but
> this
> is probably one of those situations where it makes sense to have them.
> See
> this thread for more:
>
> http://www.nabble.com/TAPESTRY-1370%3A-Where-are-the-tests-tf3887096.html#a11019346
> .
will do.
-) Why the around advice event connection? I don't see any benefit / use of
> the functionality this feature provides so am curious as to why it was
> chosen. Esp. since it costs much more performance wise than normal
> connections.
I did it for invocation.arguments. But as you explain below, there's a much
better way. So, it'll go away.
-) Still am very much against these values going in as listener
> parameters. Hard coding the sp=value stuff in to the client side is
> definitely a big no no. More reasons for not doing this are the
> unexpected
> results from calling IRequestCycle.getListenerParameters() which will now
> include these client side values. I can dig around some more but am
> fairly
> certain this is not the described behavior of this functionality. It will
> also result in the ListenerMethodInvoker service doing a lot of
> unnecessary
> work for every listener method invocation resulting from an event in the
> system - regardless of whether people want the extra values or not.. I
> can
> go on and on about the possible bad side effects but hopefully this is
> enough to support my arguments.
Yep, I'll do it your way
I'm not saying you can't make them be separate arguments from the
> BrowserEvent object, I just really think they need to be treated exactly
> like IRequestCycle/BrowserEvent as far as how ListenerMethodInvokerImpl
> handles them as optional arguments to any method. Putting the values in
> BrowserEvent may be easiest to do as far as not adding undo
> overhead/complication in the ListenerMethodInvokerImpl logic. ...This I'm
> not as sure about, so maybe you have some more ideas on it. If you can
> find a way to add listener method arguments as separate objects consisting
> of these json arguments that won't be unintuitive / conflict with normal
> listener method arguments (esp when we add the parameters ognl expression
> to
> @EventListener) then I'm open to ideas..
>
> -) ComponentEvent.script is a good start - but there is also
> ElementEvent.script/WidgetEvent.script as well as any/all possible points
> in
> the system where a listener method may be invoked asynchronously. You'd
> have to probably look at various Link components as well. (not to mention
> the form event connection logic missing in ComponentEvent.script) This
> may
> be just you checking stuff in so we can sync so if that's the case then
> sorry in advance for being anal.
>
> There may be some more refactoring I want to do to the javascript code in
> this part as well once we get closer. The native "arguments" object that
> should be referencable from any javascript function in any browser would
> be
> the preferred way to get at those arguments. If you do decide to stick
> these extra arguments in the BrowserEvent object then we should probably
> just make tapestry.buildEventProperties work solely off of the arguments
> array object.
>
> One cool thing about this object is that you can write your connection
> function like so:
>
> function handleEvent(e){
> for (var i=0; i < arguments.length; i++){}
> }
>
> And it won't matter how many argument variables like"e" we have defined in
> our function, they will always exist either way because dojo will really
> be
> calling something like <yourfunction>.apply(arguments) - which makes this
> magically possible. Not a huge deal, I can help here of course...
very good pointer. I really start to look forward getting into JS/Dojo a bit
more ...
-) buildMethodInterceptionProperties - This is a good start, but I would
> probably change a few things. I noticed you are using the
> dojo.json.serialize stuff which is good - but I took a peak at the built
> dojo.js files we have and don't think we have it in there....So we'lll
> need
> to lift that function from dojo and stick it in core + remove the
> dojo.require for it so that we don't cause any additional IO requests on
> the
> client side. This is esp. the case here as IO calls are likely to be
> included on the majority of pages so this has a big impact on page load
> times.
Yes, sorry to make you repeat that point, it's on my list. I am using
FireBug, and be assured: Once we agree on the basic impl, which, I think,
we're very close to, I do have the ambitions to make it as fast as possible.
The rest of the function implementation I think I could help with once we
> get closer to an agreed impl, it's just small js coding style / shortcut
> things that aren't super important but I'll probably be anal enough to
> want
> to change it at some point.
no problem with that, of course.
I hope my input doesn't seem too anal / etc.. I'm sure you don't and it's
it's barely anal enough! No, seriously. I do this because I enjoy
discussions like this, even and especially, when I'm the one learning most
of it.
probably redundant to say - but just in case - you always have to have a
> different frame of mind when working on framework code here and that of
> normal commercial project code. Usually (but not always) most commercial
> projects don't allow for the infinite little cycles of perfection and
> obsession over code but that is not the case here.. We don't have to
> compromise / work around things for any schedules and such. If we want
> perfection always this is the easiest place to get it because there is
> ultimately no one who will tell us what to do but ourselves. There is no
> such thing as good enough/probably not here. ...
>
> Again, please don't take the above the wrong way.. I'll only say it just
> this once but also have to remind myself of that constantly because I do
> get
> lazy here sometimes and must try to stay vigilant and keep things up to
> standard.
There, I hope that's enough initial input. :)
>
> On 6/30/07, mschulte@apache.org <ms...@apache.org> wrote:
> >
> > 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
> >
>
>
> --
> Jesse Kuhnert
> Tapestry/Dojo team member/developer
>
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
>
--
Marcus Schulte
http://marcus-schulte.blogspot.com
Re: 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
Posted by Jesse Kuhnert <jk...@gmail.com>.
Sorry it took so long to respond. I've looked things over and have some
thoughts on the changes.
-) Where are the unit tests? :) I don't always do this properly and there
are certainly cases where a feature is covered by integration tests but this
is probably one of those situations where it makes sense to have them. See
this thread for more:
http://www.nabble.com/TAPESTRY-1370%3A-Where-are-the-tests-tf3887096.html#a11019346.
-) Why the around advice event connection? I don't see any benefit / use of
the functionality this feature provides so am curious as to why it was
chosen. Esp. since it costs much more performance wise than normal
connections.
-) Still am very much against these values going in as listener
parameters. Hard coding the sp=value stuff in to the client side is
definitely a big no no. More reasons for not doing this are the unexpected
results from calling IRequestCycle.getListenerParameters() which will now
include these client side values. I can dig around some more but am fairly
certain this is not the described behavior of this functionality. It will
also result in the ListenerMethodInvoker service doing a lot of unnecessary
work for every listener method invocation resulting from an event in the
system - regardless of whether people want the extra values or not.. I can
go on and on about the possible bad side effects but hopefully this is
enough to support my arguments.
I'm not saying you can't make them be separate arguments from the
BrowserEvent object, I just really think they need to be treated exactly
like IRequestCycle/BrowserEvent as far as how ListenerMethodInvokerImpl
handles them as optional arguments to any method. Putting the values in
BrowserEvent may be easiest to do as far as not adding undo
overhead/complication in the ListenerMethodInvokerImpl logic. ...This I'm
not as sure about, so maybe you have some more ideas on it. If you can
find a way to add listener method arguments as separate objects consisting
of these json arguments that won't be unintuitive / conflict with normal
listener method arguments (esp when we add the parameters ognl expression to
@EventListener) then I'm open to ideas..
-) ComponentEvent.script is a good start - but there is also
ElementEvent.script/WidgetEvent.script as well as any/all possible points in
the system where a listener method may be invoked asynchronously. You'd
have to probably look at various Link components as well. (not to mention
the form event connection logic missing in ComponentEvent.script) This may
be just you checking stuff in so we can sync so if that's the case then
sorry in advance for being anal.
There may be some more refactoring I want to do to the javascript code in
this part as well once we get closer. The native "arguments" object that
should be referencable from any javascript function in any browser would be
the preferred way to get at those arguments. If you do decide to stick
these extra arguments in the BrowserEvent object then we should probably
just make tapestry.buildEventProperties work solely off of the arguments
array object.
One cool thing about this object is that you can write your connection
function like so:
function handleEvent(e){
for (var i=0; i < arguments.length; i++){}
}
And it won't matter how many argument variables like"e" we have defined in
our function, they will always exist either way because dojo will really be
calling something like <yourfunction>.apply(arguments) - which makes this
magically possible. Not a huge deal, I can help here of course...
-) buildMethodInterceptionProperties - This is a good start, but I would
probably change a few things. I noticed you are using the
dojo.json.serialize stuff which is good - but I took a peak at the built
dojo.js files we have and don't think we have it in there....So we'lll need
to lift that function from dojo and stick it in core + remove the
dojo.require for it so that we don't cause any additional IO requests on the
client side. This is esp. the case here as IO calls are likely to be
included on the majority of pages so this has a big impact on page load
times.
The rest of the function implementation I think I could help with once we
get closer to an agreed impl, it's just small js coding style / shortcut
things that aren't super important but I'll probably be anal enough to want
to change it at some point.
I hope my input doesn't seem too anal / etc.. I'm sure you don't and it's
probably redundant to say - but just in case - you always have to have a
different frame of mind when working on framework code here and that of
normal commercial project code. Usually (but not always) most commercial
projects don't allow for the infinite little cycles of perfection and
obsession over code but that is not the case here.. We don't have to
compromise / work around things for any schedules and such. If we want
perfection always this is the easiest place to get it because there is
ultimately no one who will tell us what to do but ourselves. There is no
such thing as good enough/probably not here. ...
Again, please don't take the above the wrong way.. I'll only say it just
this once but also have to remind myself of that constantly because I do get
lazy here sometimes and must try to stay vigilant and keep things up to
standard.
There, I hope that's enough initial input. :)
On 6/30/07, mschulte@apache.org <ms...@apache.org> wrote:
>
> 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
>
--
Jesse Kuhnert
Tapestry/Dojo team member/developer
Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com