Revision history [back]

click to hide/show revision 1
initial version

answered 2010-01-20 14:59:30 +0800

robertpic71 gravatar image robertpic71

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

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