-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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="????" />
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
Asked: 2013-10-11 14:18:01 +0800
Seen: 57 times
Last updated: Oct 14 '13