This is an automated email from the ASF dual-hosted git repository. reiern70 pushed a commit to branch reiern70/WICKET-7080 in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/reiern70/WICKET-7080 by this push: new a1d02282e9 [WICKET-7080] add remarks a1d02282e9 is described below commit a1d02282e9cd95325a896670d0b795cd9af98233 Author: reiern70 <reier...@gmail.com> AuthorDate: Wed Nov 1 12:55:53 2023 -0500 [WICKET-7080] add remarks --- .../src/main/java/org/apache/wicket/Component.java | 2 +- .../apache/wicket/settings/FrameworkSettings.java | 6 ++- .../org/apache/wicket/EventDispatcherTest.java | 48 ++++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/Component.java b/wicket-core/src/main/java/org/apache/wicket/Component.java index 4a6e382590..1b2fe94cb0 100644 --- a/wicket-core/src/main/java/org/apache/wicket/Component.java +++ b/wicket-core/src/main/java/org/apache/wicket/Component.java @@ -4446,7 +4446,7 @@ public abstract class Component public final <T> void send(IEventSink sink, Broadcast type, T payload) { // if there are no event dispatchers then don't even try to send event - if (getApplication().getFrameworkSettings().hasAnyAnyEventDispatchers()) + if (getApplication().getFrameworkSettings().hasAnyEventDispatchers()) { new ComponentEventSender(this, getApplication().getFrameworkSettings()).send(sink, type, payload); diff --git a/wicket-core/src/main/java/org/apache/wicket/settings/FrameworkSettings.java b/wicket-core/src/main/java/org/apache/wicket/settings/FrameworkSettings.java index 2f84181695..ebb82b3c95 100644 --- a/wicket-core/src/main/java/org/apache/wicket/settings/FrameworkSettings.java +++ b/wicket-core/src/main/java/org/apache/wicket/settings/FrameworkSettings.java @@ -46,7 +46,9 @@ import org.apache.wicket.util.string.Strings; public class FrameworkSettings implements IEventDispatcher { /** - * Does the standard delivery of events. Override and do nothing if you want to disable it. + * Does the standard delivery of events. Events can be disabled at application level by setting a <code>null</code> + * {@link IEventDispatcher} via {@link #setDefaultEventDispatcher(IEventDispatcher)} and setting no additional + * {@link IEventDispatcher}s (via {@link #add(IEventDispatcher)}). */ private static class DefaultEventDispatcher implements IEventDispatcher { @@ -152,7 +154,7 @@ public class FrameworkSettings implements IEventDispatcher /** * @return Returns <code>true</code> if there is at least one event dispatcher */ - public final boolean hasAnyAnyEventDispatchers() + public final boolean hasAnyEventDispatchers() { if (defaultEventDispatcher != null) { diff --git a/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java b/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java index 552cbc8b71..9b48500c87 100644 --- a/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java +++ b/wicket-core/src/test/java/org/apache/wicket/EventDispatcherTest.java @@ -17,6 +17,7 @@ package org.apache.wicket; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.annotation.ElementType; @@ -128,4 +129,51 @@ class EventDispatcherTest extends WicketTestCase } } + @Test + void noEventsDispatch() + { + tester.getApplication().getFrameworkSettings().setDefaultEventDispatcher(null); + MockPageWithOneComponent page = new MockPageWithOneComponent(); + TestComponentI testComponent = new TestComponentI(MockPageWithOneComponent.COMPONENT_ID); + page.add(testComponent); + page.send(page, Broadcast.DEPTH, null); + assertFalse(testComponent.callbackInvoked); + assertEquals(testComponent.getBehaviors(TestBehavior.class).get(0).invocationTimes, 0); + } + + public static class TestComponentI extends WebComponent + { + private static final long serialVersionUID = 1L; + boolean callbackInvoked; + + /** + * @param id + */ + TestComponentI(String id) + { + super(id); + + add(new TestBehaviorI()); + } + + @Override + public void onEvent(IEvent<?> event) { + callbackInvoked = true; + } + } + + private static class TestBehaviorI extends Behavior + { + + private static final long serialVersionUID = 1; + + int invocationTimes = 0; + + @Override + public void onEvent(Component component, IEvent<?> event) + { + invocationTimes++; + } + } + }