Listbox and button
3 Feb 2012 23:55:41 GMT
4 Feb 2012 08:41:27 GMT
4 Feb 2012 08:41:27 GMT
You can 'forward' an event method from a component to a self named method in your controller.
Mostly used for dynamically created stuff like components in a row in a listbox. If you would access such an event per component id (public void onClick$myButton(Event event){// your stuff here } you will get an 'not unique id in namespace' error. To prevent this the 'forwarding' is the best method, so you need no component ID for the Button.
(Be sure your new method name begins with onXXX. It's a naming convention in zk).
.zul
... <listcell> < button ... forward="onClick=onMyLineButtonClicked()" /> </listcell>
or rendering with java code
public class MyListItemsRenderer implements ListitemRenderer, Serializable {
private static final long serialVersionUID = 1L;
@Override
public void render(Listitem item, Object data) throws Exception {
final MyBean bean = (MyBean) data;
Listcell lc;
lc = new Listcell(myBean.getDescription());
lc.setStyle("padding-left: 5px");
lc.setParent(item);
. . .
item.setValue(data);
// ComponentsCtrl.applyForward(img, "onClick=onImageClicked");
// ComponentsCtrl.applyForward(item, "onDoubleClick=onMyItemDoubleClicked");
ComponentsCtrl.applyForward(item, "onClick=onMyLineButtonClicked");
}
in your Controller which extends the zk GenericForwardController
. . .
public void onMyLineButtonClicked(Event event){
// do your stuff here
}
best
Stephan
6 Feb 2012 18:01:52 GMT
6 Feb 2012 18:01:52 GMT
Hello
it's working fine, thanks ;)
ZK - Open Source Ajax Java Framework
Hello
I have a listbox, and i would like to add a button at the end of each line.
This button should be able to print the number of the line
<listbox id="box" multiple="true" model="@{win$composer.allProducts, load-after='add.onClick, delete.onClick, update.onClick'}" selectedItem="@{win$composer.current}"> <listhead> <listheader label="Id" /> <listheader label="Name" sort="auto(name)" /> <listheader label="Link" /> </listhead> <listitem self="@{each='e'}" value="e"> <listcell label="@{e.id}" /> <listcell label="@{e.name}" /> <listcell> <button label="Link" onClick="alert(?)" /> </listcell> </listitem> </listbox>Any idea how to do that ?
thanks
nicolas