-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a custom component which fires an event from the javascript as follows:
this.fire('onButtonClick',{}, {toServer:true});
In order to reference this event on the zul page eg:
<component onButtonClick="@command(doSomething)"/>
Do I need to add code to handle this event in the Service method of the components Java class ??
For example I usually do the following:
public void service(org.zkoss.zk.au.AuRequest request, boolean everError) {
final String cmd = request.getCommand();
if (cmd.equals("onButtonClick")) {
Event evt = Event.getEvent(request);
Events.postEvent(evt);
} else
super.service(request, everError);
}
}
Is this service method code required for the event to work on the server (ie from a zul page) ??
Thanks.
Basically no, you don't need to add the code in service method, this method is used to update component state before posting event. For example, in Listbox component, ZK will sync the selected objects/items before posting SelectEvent in the service method. If you don't have this requirement, then it is not needed.
Hi JustinFrost,
comWidget.fire() will send an ajax request to the component corresponding to comWidget. So you can use
zk.Widget.$('$comId').fire('onButtonClick',{}, {toServer:true})
to trigger the onButtonClick event.
Client-side Firing http://books.zkoss.org/wiki/ZKClient-sideReference/Communication/AURequests/Client-sideFiring
Asked: 2015-08-13 06:43:26 +0800
Seen: 99 times
Last updated: Aug 21 '15