Fire event from widget to server

asked 2015-08-13 06:43:26 +0800

JustinFrost gravatar image JustinFrost
139 1 6

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);
     } else
         super.service(request, everError);

Is this service method code required for the event to work on the server (ie from a zul page) ??


delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2015-08-21 04:47:08 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2015-08-21 04:48:53 +0800

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.

link publish delete flag offensive edit

answered 2015-08-20 10:07:52 +0800

JoeHuang gravatar image JoeHuang
1126 2

updated 2015-08-20 10:08:53 +0800

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

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2015-08-13 06:43:26 +0800

Seen: 72 times

Last updated: Aug 21 '15

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