0

Zk Multiple Composer Listitem onClick listen problem

asked 2018-01-09 20:04:36 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

I have a view with a composer that composer is using a HtmlMacroComponent to create several listboxes that macroComponent is using also a composer in the listbox i have this code

<template name="model">                                                     
 <listitem>                                             
   <listcell/>                                                                                      
   <listcell/>
   <listcell/>                                          
 </listitem>
</template>                                     
</listbox>

As you can see i am not using id in listitem because it throws Not Unique Id In Space all i want to do is listen onClick on the listitem but how it doesnt have a id i could listen to it i have try the following

@Listen("onClick=#results > listitem")
@Listen("onClick=listitem")

But nothing happens the method is never called how can i do this thanks a lot and best regards from Venezuela.

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-01-10 15:38:15 +0800

cor3000 gravatar image cor3000
4143 1 7
ZK Team

updated 2018-01-10 15:42:37 +0800

when dealing with dynamically generated listitems an easy way is to use event forwarding.

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

this will make you life a whole lot easier, since the forward event listeners are added/removed on demand, and all your application has to deal with is a single event listener at the listbox.

Robert

link publish delete flag offensive edit
0

answered 2018-01-10 15:02:18 +0800

hawk gravatar image hawk
2255 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2018-01-10 16:04:47 +0800

I found if you wire an event listener in a HtmlMacroComponent for a listitem like the code below, it doesn't wire as expected.

public class MyListbox extends HtmlMacroComponent {

    @Listen("onClick = listitem")
    public void click(){
        Clients.showNotification("click a macro");
    }
}

It looks a like a bug, I have posted it.

But usually we don't listen onClick for a listitem, you can listen onSelect on a Listbox. Or just listen to onClick event in its parent composer.

If you use ZK 8, you can replace with the macro with <apply> and a composer.

Hope those workarounds above work for you.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2018-01-09 20:04:36 +0800

Seen: 14 times

Last updated: Jan 10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More