-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm trying to call a method within my model element upon a button click. Here's my code
<listbox model="${$composer.model2}" >
<template name="model">
<listitem>
<listcell label="${each.getName()}">
<button onClick="${each.toggeSort()};"/>
</listcell>
</listitem>
</template>
</listbox>
onClick="${each.toggeSort()}; is not the right way to do it. How should this be done?
Hello Dhanasiddharth,
My personal opinion is that you should use a renderer:
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVC/View/Renderer/Listbox%20Renderer
And a renderer example:
public void render(Listitem listitem, Object obj, int index) throws Exception {
//Initialize Object
final MyObject myObject = (MyObject) obj;
listitem.appendChild(new Listcell(myObject.getXXX()));
//Add onClick record event
listitem.addEventListener("onClick", new EventListener()
{
public void onEvent(Event event)throws Exception
{
}
});
}
Best Regards,
Darksu
Asked: 2015-07-06 13:01:46 +0800
Seen: 24 times
Last updated: Jul 06 '15
if you insist on doing it inside the zul file (using interpreted beanshell, PERFORMANCE IMPACT) just do this <button onClick="each.toggeSort();"/>, for better performance use the listener approach explained by Darksu
cor3000 ( 2015-07-07 02:45:41 +0800 )edit@cor3000, using onClick="each.toggeSort();" throws error 'undefined variable or class name: each'
Dhanasiddharth ( 2015-07-07 05:23:37 +0800 )editI'll get back when I have more time
cor3000 ( 2015-07-07 11:28:38 +0800 )editsorry for missing a little step, here a running example: http://zkfiddle.org/sample/2q2qofp/1-call-method-on-model-item still registering an event listener at the java side is more performant than using inline scripting
cor3000 ( 2015-07-09 08:47:46 +0800 )editThanks. I'll try to use listener in my composer by forwarding the event to the listbox
Dhanasiddharth ( 2015-07-09 16:27:58 +0800 )edit