iank
iank

Reputation: 810

How can I log UI events in ZK?

I'm working with a large ZK / Spring application and would like to know if I can somehow add trace style logging to all of the UI elements, but without adding log statements to each individual element. (I want to be able to trace through events that are initiated from the UI.)

Thanks!

Upvotes: 2

Views: 1422

Answers (1)

kachhalimbu
kachhalimbu

Reputation: 2200

Assuming you want to log all UI events on the server side, please implement an EventInterceptor like this

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.EventInterceptor;

public class LogEventInterceptor implements EventInterceptor {

public Event beforeProcessEvent(Event event) {
    System.out.println(event.getName() + " event received for + "
            + event.getTarget().getId() + "!!!");
    return event;
}
// rest of the impl

and then configure it in your zk.xml as below (refer here for more details)

<listener>
    <listener-class>foo.LogEventInterceptor</listener-class>
</listener>

For a simple zul file like this

<window border="normal" title="Intercepting UI Events demo">
    <button id="helloBtn" label="Click me to Say hello"
        onClick='alert("Hello !!!")'>
    </button>
</window>

then clicking on helloBtn will generate following log on server console

onClick event received for + helloBtn !!!

Upvotes: 2

Related Questions