Skip to content

Commit

Permalink
[WICKET-7080] add remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
reiern70 committed Nov 1, 2023
1 parent 756ff28 commit a1d0228
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wicket-core/src/main/java/org/apache/wicket/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -4446,7 +4446,7 @@ public void onEvent(IEvent<?> event)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
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
{
Expand Down Expand Up @@ -152,7 +154,7 @@ public FrameworkSettings add(IEventDispatcher dispatcher)
/**
* @return Returns <code>true</code> if there is at least one event dispatcher
*/
public final boolean hasAnyAnyEventDispatchers()
public final boolean hasAnyEventDispatchers()
{
if (defaultEventDispatcher != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,4 +129,51 @@ public void testCallback()
}
}

@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++;
}
}

}

0 comments on commit a1d0228

Please sign in to comment.