-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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.
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
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.
Asked: 2018-01-09 20:04:36 +0800
Seen: 16 times
Last updated: Jan 10 '18
wrong valueException come in front of modal popup [closed]
Use parameters in a conditional @command
Problems with multiple press and onCtrlKey
MVVM @save on the fly [closed]
Unable to activate destroyed desktop
org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException
How to put a image or Letter over image on a specific XY Coordinate