Wicket
  1. Wicket
  2. WICKET-214

Call all behaviors attached to the same event

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 1.4-M1
    • Fix Version/s: None
    • Component/s: wicket
    • Labels:
      None

      Description

      If one adds 2 AjaxFormComponentUpdatingBehaviors with event "onchange" to the same form component, only the behavior that was added last will actually be called. Please make it so that both are called.

        Issue Links

          Activity

          Hide
          Igor Vaynberg added a comment -

          behvaiors:ajax calls is not always 1:1. some behaviors are purely clientside. also, this comes up often so we should offer the devs a choice to do this even if it can have unwanted sideeffects.

          Show
          Igor Vaynberg added a comment - behvaiors:ajax calls is not always 1:1. some behaviors are purely clientside. also, this comes up often so we should offer the devs a choice to do this even if it can have unwanted sideeffects.
          Hide
          Martin Grigorov added a comment -

          Here is a behavior based on JQuery.bind() that allows that.
          I created it to show how to use JQuery's mouseenter/mouseleave events but it can be used for this case too.

          I believe that assigning several behaviors on the same event is bad practice because this will make several Ajax calls to the server side. Better do one call and then at the server side delegate to all interested parties.

          Show
          Martin Grigorov added a comment - Here is a behavior based on JQuery.bind() that allows that. I created it to show how to use JQuery's mouseenter/mouseleave events but it can be used for this case too. I believe that assigning several behaviors on the same event is bad practice because this will make several Ajax calls to the server side. Better do one call and then at the server side delegate to all interested parties.
          Hide
          Anders Båtstrand added a comment -

          I just ran into this problem, and do not understand the last comment. Is this issue solved? Would it be possible with some hints for how developer should attach multiple behaviours to the same event?

          Show
          Anders Båtstrand added a comment - I just ran into this problem, and do not understand the last comment. Is this issue solved? Would it be possible with some hints for how developer should attach multiple behaviours to the same event?
          Hide
          Pedro Santos added a comment -

          I think we did allow users to delegate AJAX calls to their behavior as they want with the new event dispatcher API.

          Show
          Pedro Santos added a comment - I think we did allow users to delegate AJAX calls to their behavior as they want with the new event dispatcher API.
          Hide
          Bruno Borges added a comment -

          I've been trying to implement something like IMergeableBehavior, but because of so many specific properties each behavior can provide, I think it won't be a good idea.

          Maybe other things must be considered to solve this:

          1) Defining an IEventBehavior - which would serve for Javascript events only, like onChange, etc...

          interface IEventBehavior extends IBehavior, IHeaderContributor

          { public String getEvent(); }

          2) Defining a class called AggregatedEventBehavior - which would... aggregate IEventBehaviors of the same event type

          class AggregatedEventBehavior {
          public AggregatedEventBehavior(IEventBehavior... events)

          { ... // check for event type consistency }

          .. // other methos like render, onComponentTag, etc, like in IBehavior
          }

          3) Only one ajax call to this aggregated behavior (avoiding multiple Ajax calls)

          4) If developer choses to add more than one event of the same type to a component, the framework should throw an exception. If the intention is to actually attach more than one behavior to the same event, the developer will have to use an IAggregatedEventBehavior

          5) The need of a new method: Component.add(AggregatedEventBehavior)

          6) Somehow, avoid the use of AttributeModifiers that refers to Javascript events

          Cheers,
          Bruno

          Show
          Bruno Borges added a comment - I've been trying to implement something like IMergeableBehavior, but because of so many specific properties each behavior can provide, I think it won't be a good idea. Maybe other things must be considered to solve this: 1) Defining an IEventBehavior - which would serve for Javascript events only , like onChange, etc... interface IEventBehavior extends IBehavior, IHeaderContributor { public String getEvent(); } 2) Defining a class called AggregatedEventBehavior - which would... aggregate IEventBehaviors of the same event type class AggregatedEventBehavior { public AggregatedEventBehavior(IEventBehavior... events) { ... // check for event type consistency } .. // other methos like render, onComponentTag, etc, like in IBehavior } 3) Only one ajax call to this aggregated behavior (avoiding multiple Ajax calls) 4) If developer choses to add more than one event of the same type to a component, the framework should throw an exception. If the intention is to actually attach more than one behavior to the same event, the developer will have to use an IAggregatedEventBehavior 5) The need of a new method: Component.add(AggregatedEventBehavior) 6) Somehow, avoid the use of AttributeModifiers that refers to Javascript events Cheers, Bruno
          Hide
          Johan Compagner added a comment -

          moving to 1.4.0
          This won't make it for 1.3

          Show
          Johan Compagner added a comment - moving to 1.4.0 This won't make it for 1.3
          Hide
          Eelco Hillenius added a comment -

          Assigned version (beta 4)

          Show
          Eelco Hillenius added a comment - Assigned version (beta 4)
          Hide
          Alastair Maw added a comment -

          I don't think this is going to make 1.3.0. Unscheduling for the time being.

          Show
          Alastair Maw added a comment - I don't think this is going to make 1.3.0. Unscheduling for the time being.
          Hide
          Erik van Oosten added a comment -

          The situation would already be improved a lot if the javadoc would make it clear that it is not possible to add multiple behaviors to the same event.

          Yet another option is to provide an aggregation behavior. Something that would allow you to merge 2 behaviors into 1. I am not sure how this could work.

          I am not familiar with Wicket.Event (a 1.3 feature?).

          Show
          Erik van Oosten added a comment - The situation would already be improved a lot if the javadoc would make it clear that it is not possible to add multiple behaviors to the same event. Yet another option is to provide an aggregation behavior. Something that would allow you to merge 2 behaviors into 1. I am not sure how this could work. I am not familiar with Wicket.Event (a 1.3 feature?).
          Hide
          Matej Knopp added a comment -

          I don't really like this. We could use Wicket.Event for attaching events on to component instead of the attributes, but this would result in multiple ajax calls. I doubt that this is desirable.

          Show
          Matej Knopp added a comment - I don't really like this. We could use Wicket.Event for attaching events on to component instead of the attributes, but this would result in multiple ajax calls. I doubt that this is desirable.
          Hide
          Igor Vaynberg added a comment -

          i dont like what you propose, but i wont -1 it either, so go ahead.

          Show
          Igor Vaynberg added a comment - i dont like what you propose, but i wont -1 it either, so go ahead.
          Hide
          Johan Compagner added a comment -

          i would say just call all ajax events that are on the same event.
          Why not that can be explained perfectly. Ajax works but if you have pure client side scripts it could fail
          (it could! because we still have already the ability to merge the behaviors!, so that you can prepend or append!)

          Show
          Johan Compagner added a comment - i would say just call all ajax events that are on the same event. Why not that can be explained perfectly. Ajax works but if you have pure client side scripts it could fail (it could! because we still have already the ability to merge the behaviors!, so that you can prepend or append!)
          Hide
          Igor Vaynberg added a comment -

          there is really no good way to do this that will work across the board. if we do it for ajax then people will want it for other things as well

          one compromise i can think of is to do this: iterate over behaviors that implement the invoked listener interface and call equals on them - if they are equal then invoke the listener on them as well

          is this a good compromise?

          Show
          Igor Vaynberg added a comment - there is really no good way to do this that will work across the board. if we do it for ajax then people will want it for other things as well one compromise i can think of is to do this: iterate over behaviors that implement the invoked listener interface and call equals on them - if they are equal then invoke the listener on them as well is this a good compromise?
          Hide
          Eelco Hillenius added a comment -

          This has been discussed on the user list as well if I'm correctly. I thought the consensus was not to do anything about it, though error reporting could be improved?

          Show
          Eelco Hillenius added a comment - This has been discussed on the user list as well if I'm correctly. I thought the consensus was not to do anything about it, though error reporting could be improved?

            People

            • Assignee:
              Igor Vaynberg
              Reporter:
              Erik van Oosten
            • Votes:
              3 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development