0

Wiring event listeners from a template

asked 2013-10-11 14:18:01 +0800

s3lvatico gravatar image s3lvatico
22 2

Greetings, everyone.

I have a Listbox inside a Window controlled by a SelectorComposer. The Listbox is populated by a model coming from the composer, and in the last column I placed a Button. (in this way, each row in the listbox has a button with a unique id).

<window id="wndMain" apply="com.example.MainComposer">
...
  <listbox model="${wndMain$composer.leModel}" id="lbx">
     <listhead>
        <listheader label="Code"/>
        ...
        <listheader label="Active"/>
     </listhead>
     <template name="model">
        <listitem>
           <listcell label="${each.code}" />
           ...
           <listcell>
              <button id="${each.code}" label="Make Active" class="selectionButton"  />
           </listcell>
        </listitem>
     </template>
   </listbox>
</window>

Now, I'd like to wire the onClick event of each button with a single event listener defined inside the composer.

I tried the following approach inside the composer:

@Listen("onClick = button.selectionButton")
public void selectStuff(MouseEvent evt) {      
   Component target = evt.getTarget();
   String clickedRowCode = target.getId();
   System.out.println("you clicked on: " + clickedRowCode);
}

but at runtime there is no interaction between the components and the composer.

I imagine that the cause of this is that the actual wiring happens during the invocation of super.doAfterCompose(...) and there is no wiring done when the listbox rows are dynamically created.

So I'd like to do the other way around, that is referencing the event handler of the composer directly from the ZUL file.

What is the correct syntax to use in this case?

<button id="${each.code}" label="Make Active" onClick="????" />
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-10-14 02:28:04 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

the wiring in doing when afterCompose and at that time, there is no listitem/button yet.

I suggest you to forward the onClick event of button (in each listitem) to the listbox like

<button id="${each.code}" label="Make Active" class="selectionButton" onClick='lbx.onSomeClick'  />

And in composer

@Listen("onSomeClick = #lbx")
public void selectStuff(ForawrdEvent evt) {}

read http://books.zkoss.org/wiki/ZKDeveloper'sReference/EventHandling/EventForwarding

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
2 followers

RSS

Stats

Asked: 2013-10-11 14:18:01 +0800

Seen: 54 times

Last updated: Oct 14 '13

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