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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 8.5.0
    • Fix Version/s: 8.5.2
    • Component/s: None
    • Security Level: Jimmy
    • Labels:
      None
    • gh.sprint.customfield.default.name:
      ZK 8.5.2 S1

      Description

      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();
      }
      

        Attachments

        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

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

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