-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
You have do handle the event. The event contains the targetComponent.
Here is example (working insde the ZK Demo page) with custom-attribute (custom-attribute working since 5.0 with databinding): Note: I store the value inside the customattribute. This could be a value of the object (here: person.firstName) or the object itself --> value=@{value} if you want the whole object.
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./mywin"?>
<window id="mywin" border="none">
ZK name check list :
<zscript>
//init example data beans
import org.zkoss.zkdemo.userguide.Person;
List persons = new ArrayList();
persons.add(new Person("Balu", "Haben"));
persons.add(new Person("Sadira", "Jobs"));
persons.add(new Person("Dacey", "Obert"));
persons.add(new Person("Gabby", "Taffy"));
Person selected = persons.get(0);
void someFunction(Event event) {
option.value = event.getTarget().getAttribute("value");
}
</zscript>
Option:<label id="option"/>
<listbox model="@{persons}" selectedItem="@{selected}" rows="5">
<listhead >
<listheader label="Name"/>
</listhead>
<listitem self="@{each=person}">
<listcell>
<toolbarbutton onClick="someFunction(event)" label="@{person.fullName}">
<custom-attributes value="@{person.firstName}"/>
</toolbarbutton>
</listcell>
</listitem>
</listbox>
</window>
However, you get the component form the event. You could also retrieve the "mother" toolbarbutton - getParent() --> listcell - getParent() --> listitem.
Check this thread for another example.
/Robert