You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2008/02/19 21:47:27 UTC

svn commit: r629224 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry: annotations/ corelib/components/ internal/services/ runtime/

Author: hlship
Date: Tue Feb 19 12:47:25 2008
New Revision: 629224

URL: http://svn.apache.org/viewvc?rev=629224&view=rev
Log:
TAPESTRY-2177: Conversion of context parameters to server-side objects uses the TypeCoercer rather than the correct ValueEncoder

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/annotations/OnEvent.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/annotations/OnEvent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/annotations/OnEvent.java?rev=629224&r1=629223&r2=629224&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/annotations/OnEvent.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/annotations/OnEvent.java Tue Feb 19 12:47:25 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 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.
@@ -29,7 +29,7 @@
  * <p/>
  * Client events include a <em>context</em> of one or more values. These context values are
  * included in the action URI. The values are optionally supplied to the handler method as
- * parameters. Automatic type coercions from string to the type of the actual parameter occur.
+ * parameters. Automatic {@linkplain org.apache.tapestry.ValueEncoder conversion} from string to the type of the actual parameter occur.
  * <p/>
  * Handlers may return a value. Returning a non-null value will abort the handling of the event, and
  * will usually control the response sent to the client web browser. The details are somewhat

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java?rev=629224&r1=629223&r2=629224&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Form.java Tue Feb 19 12:47:25 2008
@@ -301,7 +301,7 @@
     }
 
     @SuppressWarnings({"unchecked", "InfiniteLoopStatement"})
-    Object onAction(Object[] context) throws IOException
+    Object onAction(EventContext context) throws IOException
     {
         _tracker.clear();
 
@@ -321,11 +321,11 @@
             ComponentResultProcessorWrapper callback = new ComponentResultProcessorWrapper(
                     _componentEventResultProcessor);
 
-            _resources.triggerEvent(PREPARE_FOR_SUBMIT, context, callback);
+            _resources.triggerContextEvent(PREPARE_FOR_SUBMIT, context, callback);
 
             if (callback.isAborted()) return true;
 
-            _resources.triggerEvent(PREPARE, context, callback);
+            _resources.triggerContextEvent(PREPARE, context, callback);
 
             if (callback.isAborted()) return true;
 
@@ -380,7 +380,7 @@
 
             _tracker = tracker;
 
-            _resources.triggerEvent(VALIDATE_FORM, context, callback);
+            _resources.triggerContextEvent(VALIDATE_FORM, context, callback);
 
             if (callback.isAborted()) return true;
 
@@ -395,13 +395,13 @@
 
             if (!_tracker.getHasErrors()) _tracker.clear();
 
-            _resources.triggerEvent(tracker.getHasErrors() ? FAILURE : SUCCESS, context, callback);
+            _resources.triggerContextEvent(tracker.getHasErrors() ? FAILURE : SUCCESS, context, callback);
 
             // Lastly, tell anyone whose interested that the form is completely submitted.
 
             if (callback.isAborted()) return true;
 
-            _resources.triggerEvent(SUBMIT, context, callback);
+            _resources.triggerContextEvent(SUBMIT, context, callback);
 
             return callback.isAborted();
         }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java?rev=629224&r1=629223&r2=629224&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java Tue Feb 19 12:47:25 2008
@@ -85,4 +85,9 @@
 
         return result;
     }
+
+    public EventContext getEventContext()
+    {
+        return _context;
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java?rev=629224&r1=629223&r2=629224&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java Tue Feb 19 12:47:25 2008
@@ -14,22 +14,24 @@
 
 package org.apache.tapestry.internal.services;
 
+import org.apache.tapestry.EventContext;
 import org.apache.tapestry.annotations.OnEvent;
 import org.apache.tapestry.ioc.util.BodyBuilder;
 import org.apache.tapestry.model.MutableComponentModel;
-import org.apache.tapestry.runtime.Component;
 import org.apache.tapestry.services.*;
 
 import java.util.List;
 
 /**
- * Provides implementations of the {@link Component#dispatchComponentEvent(org.apache.tapestry.runtime.ComponentEvent)}
- * method, based on {@link OnEvent} annotations.
+ * Provides implementations of the {@link org.apache.tapestry.runtime.Component#dispatchComponentEvent(org.apache.tapestry.runtime.ComponentEvent)}
+ * method, based on {@link org.apache.tapestry.annotations.OnEvent} annotations.
  */
 public class OnEventWorker implements ComponentClassTransformWorker
 {
     static final String OBJECT_ARRAY_TYPE = "java.lang.Object[]";
 
+    static final String EVENT_CONTEXT_TYPE = EventContext.class.getName();
+
     private final static int ANY_NUMBER_OF_PARAMETERS = -1;
 
     public void transform(final ClassTransformation transformation, MutableComponentModel model)
@@ -149,10 +151,13 @@
 
         if (types.length == 0) return 0;
 
-        if (types[0].equals(OBJECT_ARRAY_TYPE)) return ANY_NUMBER_OF_PARAMETERS;
+        if (types.length == 1)
+        {
+            String soloType = types[0];
 
-        // TODO: If the first parameter is Object[], that should be the only parameter.
-        // Otherwise, Object[] should not be allowed.
+            if (soloType.equals(OBJECT_ARRAY_TYPE) || soloType.equals(EVENT_CONTEXT_TYPE))
+                return ANY_NUMBER_OF_PARAMETERS;
+        }
 
         return types.length;
     }
@@ -172,6 +177,14 @@
             if (type.equals(OBJECT_ARRAY_TYPE))
             {
                 builder.add("$1.getContext()");
+                continue;
+            }
+
+            // Added for TAPESTRY-2177
+
+            if (type.equals(EVENT_CONTEXT_TYPE))
+            {
+                builder.add("$1.getEventContext()");
                 continue;
             }
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java?rev=629224&r1=629223&r2=629224&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java Tue Feb 19 12:47:25 2008
@@ -15,6 +15,7 @@
 package org.apache.tapestry.runtime;
 
 import org.apache.tapestry.ComponentResourcesCommon;
+import org.apache.tapestry.EventContext;
 
 /**
  * An event that may originate in application logic, or as a result of a client interaction (a GET or POST from the
@@ -46,7 +47,12 @@
     Object coerceContext(int index, String desiredTypeName);
 
     /**
-     * Returns the raw context as a (possibly empty) array.
+     * Returns the underlying {@link org.apache.tapestry.EventContext} as a (possibly empty) array.
      */
     Object[] getContext();
+
+    /**
+     * Returns the underlying event context.
+     */
+    EventContext getEventContext();
 }