Wicket
  1. Wicket
  2. WICKET-5339

Broadcast.EXACT does not notify Behaviors of target Component

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.11.0, 7.0.0-M1
    • Component/s: wicket
    • Labels:
      None

      Description

      As described in IRC I want to "answer" an event by sending an event back to events source using broadcast exact. But that answer should be handled by a Behavior on the component.

      When using any other broadcast type behaviors will be notified too. But not when using exact. Since Behavior does not implement IEventSink I cannot address the behavior directly instead of the component. Even if that works I think it wont be a good practice.

      I'm not sure if this is a bug, since it's a philosophic question if exact broadcast should include behaviors of a component.

      1. event_quickstart-working.tgz
        31 kB
        Martin Grigorov
      2. event_quickstart.zip
        60 kB
        Martin Sturm
      3. broadcast-exact.patch
        11 kB
        Martin Grigorov

        Issue Links

          Activity

          Hide
          Martin Sturm added a comment - - edited

          Application.get().getFrameworkSettings().add(new IEventDispatcher() {
          @Override
          public void dispatchEvent(Object sink, IEvent<?> event, Component component) {
          if (sink instanceof Component && Broadcast.EXACT.equals(event.getType())){
          Component componentSink = (Component) sink;
          List<? extends Behavior> behaviors = componentSink.getBehaviors();
          for (Behavior behavior : behaviors)

          { behavior.onEvent(componentSink, event); }

          }
          }
          });

          Did it for me as workaround until release.

          Show
          Martin Sturm added a comment - - edited Application.get().getFrameworkSettings().add(new IEventDispatcher() { @Override public void dispatchEvent(Object sink, IEvent<?> event, Component component) { if (sink instanceof Component && Broadcast.EXACT.equals(event.getType())){ Component componentSink = (Component) sink; List<? extends Behavior> behaviors = componentSink.getBehaviors(); for (Behavior behavior : behaviors) { behavior.onEvent(componentSink, event); } } } }); Did it for me as workaround until release.
          Hide
          Martin Grigorov added a comment -

          From now on if the sink is a Component instance then all its behaviors are notified as well.

          Show
          Martin Grigorov added a comment - From now on if the sink is a Component instance then all its behaviors are notified as well.
          Hide
          Martin Sturm added a comment -

          I can pass the Behavior - thats waiting for answer - as payload or attribute of my payload to ...

          Show
          Martin Sturm added a comment - I can pass the Behavior - thats waiting for answer - as payload or attribute of my payload to ...
          Hide
          Martin Sturm added a comment - - edited

          The patch seems to be ok. I would like it more if my answering component must not know the behaviors implementation or class. Otherwise I could do:

          ((Component)event.getSource()).getBehaviors(MagicBehavior.class).get( ? ).doMagicStuff(...)

          So maybe Behavior needs to implement IEventSource so that I can send the answer directly to the Behavior which I will get from event.getSource() ... ?

          Show
          Martin Sturm added a comment - - edited The patch seems to be ok. I would like it more if my answering component must not know the behaviors implementation or class. Otherwise I could do: ((Component)event.getSource()).getBehaviors(MagicBehavior.class).get( ? ).doMagicStuff(...) So maybe Behavior needs to implement IEventSource so that I can send the answer directly to the Behavior which I will get from event.getSource() ... ?
          Hide
          Martin Grigorov added a comment -

          A patch that allows to send events to specific IComponentAwareEventSink

          Show
          Martin Grigorov added a comment - A patch that allows to send events to specific IComponentAwareEventSink
          Hide
          Martin Grigorov added a comment -

          Here is a modified quickstart that workarounds the problem

          The main problem is that Behavior is I*ComponentAware*EventSink, and there is no Component to pass to #onEvent(Component, IEvent).
          So I made your Behavior implementing IEventSink.

          Show
          Martin Grigorov added a comment - Here is a modified quickstart that workarounds the problem The main problem is that Behavior is I*ComponentAware*EventSink, and there is no Component to pass to #onEvent(Component, IEvent). So I made your Behavior implementing IEventSink.
          Hide
          Martin Sturm added a comment -

          Quick start that doesn"t work for me.

          Show
          Martin Sturm added a comment - Quick start that doesn"t work for me.

            People

            • Assignee:
              Martin Grigorov
              Reporter:
              Martin Sturm
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development