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

wire an event listener doesn't work for a Listitem in HtmlMacroComponent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 8.5.2
    • 8.5.0
    • None
    • Security Level: Jimmy
    • None
    • ZK 8.5.2 S1

      Steps to Reproduce

      1. run the attached zul
      2. click a listitem

      Current Result

      nothing appears

      Expected Result

      a notification appears

      Debug Information

      • if a listitem is statically written in a zul, no issue. If we create a listitem in a template, this issue happens.
      • SelectorComposer wires event listeners as expected for comp.addEventListener("onCreate", new AfterCreateWireListener());
      • Even with SelectorComposer, we can't listen onClick for dynamically-created listitem e.g. if one listitem is added when clicking a button, ZK doesn't wire it with onClick listener, we need a better way to listen to events for dynamically-created components.

      Workaround

      • replace macro with <apply>
      • use "forward" event
        <listbox id="myListbox">
          <template name="model">
            <listitem forward="onClick=myListbox.onItemClick(${each})">
              <listcell/>
              <listcell/>
              <listcell/>
            </listitem>
          </template>
        </listbox>
        

      then you can create a listener:

      @Listen("onItemClick=#myListbox")
      public void onItemClick(ForwardEvent event) {
          //get the data passed into the forward event
          Object each = event.getData();
          //get the original MouseEvent and click target
          MouseEvent me = (MouseEvent) event.getOrigin();
          Listitem listitem = me.getTarget();
      }
      

        1. MyListbox.java
          0.4 kB
        2. t5220.zul
          0.2 kB
        3. T5220Composer.java
          0.3 kB
        4. t5220-mylistbox.zul
          0.5 kB

            klyvechen klyvechen
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 2 days
                2d
                Remaining:
                Remaining Estimate - 2 days
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified