-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi. I am new on Zk and I stuck while using checkbox with onChek method. I have one .zul file as View and EventController.java class for controller class. I want to call method in EventController when I check chekbox but It gaves me Not an event name error. Here my .zul and java fıle
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?> <window id="win" title="To do list" width="1000px" border="normal" apply="com.ercan.todolist.EventController"> <listbox id="box" multiple="true" rows="5" model="@{win$composer.AllProducts, load-after='add.onClick, delete.onClick, update.onClick , calculate.onClick'}" selectedItem="@{win$composer.current}"> <listhead> <listheader label="Product_Name" /> <listheader label="Category" width="50px" /> <listheader label="Quant" width="50px" /> <listheader label="Date" width="90px" /> </listhead> <listitem self="@{each='event'}" value="@{event}"> <listcell label="@{event.name}" /> <listcell label="@{event.cat}" /> <listcell label="@{event.quant}" /> <listcell label="@{event.date}" /> </listitem> </listbox> <checkbox id="a" label="deneme" forward="onCheck=win.doCheck"/> <groupbox> <caption label="Event" /> Name: <textbox id="name" cols="25" value="@{win$composer.current.name}" /> Category: <textbox id="cat" cols="25" value="@{win$composer.current.cat}" /> Quant: <intbox id="quant" cols="1" value="@{win$composer.current.quant}" /> Date: <datebox id="date" cols="8" value="@{win$composer.current.date}" /> <button id="add" label="Add" width="36px" height="24px"/> <button id="update" label="Update" width="46px" height="24px"/> <button id="delete" label="Delete" width="46px" height="24px"/> <button id="calculate" label="Calculate" width="46px" height="24px"/> </groupbox> </window>
And EventController.java fıle
package com.ercan.todolist; import java.util.List; import java.util.UUID; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.ForwardEvent; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Listbox; import org.zkoss.zul.api.Checkbox; public class EventController extends GenericForwardComposer { /** * */ private static final long serialVersionUID = 1L; Product current = new Product(); ProductEvent prodevt = new ProductEvent(); Listbox box; public Product getCurrent() { return current; } public void setCurrent(Product current) { this.current = current; } public List getAllProducts() { return prodevt.showAll(); } public void onClick$add() { System.out.println("called ADD"); Product newProd = new Product(current.getName(), current.getCat(), current.getQuant(), current.getDate()); prodevt.insert(newProd); } public void onClick$update() { System.out.println("called Update"); if (box.getSelectedItem() != null) { prodevt.update((Product) box.getSelectedItem().getValue()); } } public void onClick$delete() { if (box.getSelectedItem() != null) { prodevt.delete((Product) box.getSelectedItem().getValue()); } } public void onClick$calculate() { if (box.getSelectedItem() != null) { System.out.println("calculating"); prodevt.calculate(box.getItems()); System.out.println("sendedt to calculate functýon "); } } public void doCheck(ForwardEvent event) { Event orig = event.getOrigin(); System.out.println("here " + orig); } }
Meko,
Try doing your checkbox like this:
<zk> <zscript> import org.zkoss.zk.ui.util.GenericForwardComposer; public class EventController extends GenericForwardComposer { public void onCheckBox(Event event) { Object myObj = event.getOrigin().getTarget().isChecked(); alert("Checkbox value = " + myObj); } } </zscript> <window id="win" title="To do list" width="1000px" border="normal" apply="EventController"> <checkbox label="deneme" forward="onCheck=onCheckBox()" /> </window> </zk>
Maybe that will work better for you.
Todd
Just make sure you call the method that you're calling onWhatever (starting with an on)...
Hi Sparkeyspider
I had similar problem. Can you please look my new post
http://www.zkoss.org/forum/listComment/19336-Help-on-ZK-MVC-Made-Easy
So the event name should be always start on and then we have any words ?
Senthil M
Asked: 2010-12-01 02:08:13 +0800
Seen: 830 times
Last updated: Apr 24 '12