MVC Modify model object in zul

asked 2015-07-06 13:01:46 +0800

Dhanasiddharth gravatar image Dhanasiddharth flag of India
26 2

updated 2015-07-06 13:07:09 +0800

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">
                    <listcell label="${each.getName()}">
                        <button onClick="${each.toggeSort()};"/>

onClick="${each.toggeSort()}; is not the right way to do it. How should this be done?

delete flag offensive retag edit


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 )edit

I'll get back when I have more time

cor3000 ( 2015-07-07 11:28:38 +0800 )edit

sorry 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 )edit

Thanks. 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

1 Answer

Sort by ยป oldest newest most voted

answered 2015-07-06 13:20:04 +0800

Darksu gravatar image Darksu
1991 1 4

Hello Dhanasiddharth,

My personal opinion is that you should use a renderer:


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,


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

1 follower



Asked: 2015-07-06 13:01:46 +0800

Seen: 19 times

Last updated: Jul 06 '15

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