Author: mgrigorov
Date: Tue Mar 15 22:07:16 2011
New Revision: 1081961

URL: http://svn.apache.org/viewvc?rev=1081961&view=rev
Log:
WICKET-3516 Add behaviors to the event processing chain

Notify component's behaviors as well if they implement IEventSink.


Modified:
    
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ComponentEventSender.java
    
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java

Modified: 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ComponentEventSender.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ComponentEventSender.java?rev=1081961&r1=1081960&r2=1081961&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ComponentEventSender.java
 (original)
+++ 
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/ComponentEventSender.java
 Tue Mar 15 22:07:16 2011
@@ -16,6 +16,9 @@
  */
 package org.apache.wicket;
 
+import java.util.List;
+
+import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.event.Broadcast;
 import org.apache.wicket.event.IEventSink;
 import org.apache.wicket.event.IEventSource;
@@ -277,6 +280,22 @@ final class ComponentEventSender impleme
                                visit.stop();
                        }
 
+                       List<? extends Behavior> behaviors = 
object.getBehaviors();
+                       for (Behavior behavior : behaviors)
+                       {
+                               if (behavior instanceof IEventSink)
+                               {
+                                       IEventSink behaviorSink = 
(IEventSink)behavior;
+                                       dispatcher.dispatchEvent(behaviorSink, 
e);
+                                       if (e.isStop())
+                                       {
+                                               visit.stop();
+                                               break;
+                                       }
+                               }
+                       }
+
+
                        if (e.isShallow())
                        {
                                visit.dontGoDeeper();

Modified: 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java?rev=1081961&r1=1081960&r2=1081961&view=diff
==============================================================================
--- 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java
 (original)
+++ 
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java
 Tue Mar 15 22:07:16 2011
@@ -22,6 +22,7 @@ import java.lang.annotation.RetentionPol
 import java.lang.annotation.Target;
 import java.lang.reflect.Method;
 
+import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.event.Broadcast;
 import org.apache.wicket.event.IEvent;
 import org.apache.wicket.event.IEventSink;
@@ -45,11 +46,12 @@ public class EventDispatcherTest extends
                page.add(testComponent);
                page.send(page, Broadcast.DEPTH, null);
                assertTrue(testComponent.callbackInvoked);
+               
assertEquals(testComponent.getBehaviors(TestBehavior.class).get(0).invokationTimes,
 2);
        }
 
        @Retention(RetentionPolicy.RUNTIME)
        @Target(ElementType.METHOD)
-       @interface EvenCallback {
+       @interface EventCallback {
 
        }
 
@@ -61,7 +63,7 @@ public class EventDispatcherTest extends
                        Method[] sinkMethods = sink.getClass().getMethods();
                        for (int i = 0; i < sinkMethods.length; i++)
                        {
-                               if 
(sinkMethods[i].isAnnotationPresent(EvenCallback.class))
+                               if 
(sinkMethods[i].isAnnotationPresent(EventCallback.class))
                                {
                                        try
                                        {
@@ -88,14 +90,35 @@ public class EventDispatcherTest extends
                public TestComponent(String id)
                {
                        super(id);
+
+                       add(new TestBehavior());
                }
 
                /** */
-               @EvenCallback
+               @EventCallback
                public void testCallback()
                {
                        callbackInvoked = true;
                }
        }
 
+       private static class TestBehavior extends Behavior implements IEventSink
+       {
+
+               private static final long serialVersionUID = 1;
+
+               int invokationTimes = 0;
+
+               public void onEvent(IEvent<?> event)
+               {
+                       invokationTimes++;
+               }
+
+               @EventCallback
+               public void testCallback()
+               {
+                       invokationTimes++;
+               }
+       }
+
 }


Reply via email to