Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-2582

Allow specification of Priority for SelectorComposer's @Listen() Annotation

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 8.0.2
    • 7.0.4
    • Components, Databind 2
    • None
    • ZK 8.0.2 S2

      Hi,

      it would be great to have a way to specify the priority of an eventhandler in the @Listen() annotation.
      In my case i'm using databinding to update / validate / parse the value and save it to a java pojo. Additionally i have some business logic in the controller class business logic that does some additional work after the value has be changed. So it would be great to have the business logic triggered after the value is validated and my pojo is updated. By default, the @Listen("onChange = #component") bind's an event listener with prio 0 and so it might be triggered before the databinding has finished it's work. For me it would simplify things if it would be possible to specify a priority in the annotation, like @Listen("onChange(-100) = #component") to ensure that the logic is started after the databinder has finished it's job.

      I've patched org/zkoss/zk/ui/select/Selectors.java so it parses a priority specified in brackets of the event name to make it working for me. Is it possible to implement similar functionality to the upstream release? You find my patch attached and can use it if you want...

      Thanks & Bye,
      Chris

      ----------

      — org/zkoss/zk/ui/select/Selectors.java.orig 2015-01-07 13:18:05.000000000 +0100
      +++ org/zkoss/zk/ui/select/Selectors.java 2015-01-07 13:26:39.000000000 +0100
      @@ -210,6 +210,13 @@
      Iterable<Component> iter = iterable(component, strs[1]);
      // no forwarding, just add to event listener
      Set<Component> rewired = rewire ? new HashSet<Component>() : null;
      + int prio = 0;
      + int idx = name.indexOf('(');
      + if (idx > 0)

      { + int li = name.indexOf(')'); + prio = Integer.parseInt(name.substring(idx+1, li)); + name = name.substring(0, idx); + }

      for (Component c : iter) {
      if (rewired != null && !rewired.contains(c))

      { rewired.add(c); @@ -225,7 +232,7 @@ String mhash = name + "#" + method.toString(); if (set.contains(mhash)) continue; - c.addEventListener(name, new ComposerEventListener(method, controller)); + c.addEventListener(prio, name, new ComposerEventListener(method, controller)); set.add(mhash); }

      }

            wenninghsu wenninghsu
            christian christian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours
                4h