Event Listener

ZK supports to add an event listener on zul or in Java, please refer to ZK Developer’s Reference/Event Handling/Event Listening.

Supported Events

The ZK Calendar will fire events below:

CalendarsEvent.ON_ITEM_CREATE

This event is triggered when a user clicks an empty cell in the time cell.

 center Event name in 2.1: ON_EVENT_CREATE (onEventCreate)

CalendarsEvent.ON_ITEM_EDIT

This event is triggered when a user clicks on an existing calendar item.

Event name in 2.1: ON_EVENT_EDIT(onEventEdit)

CalendarsEvent.ON_ITEM_UPDATE

This event is triggered when a user drags to change a calendar item’s time span or drags to move the item to a different date.

Event name in 2.1: ON_EVENT_UPDATE(onEventUpdate)

CalendarsEvent.ON_ITEM_TOOLTIP

It’s fired when you hover a mouse on a calendar item. Listen to this event to show a tooltip for an item.

    @Listen(CalendarsEvent.ON_ITEM_TOOLTIP +"= calendars")
    public void showTooltip(CalendarsEvent event) {
        tooltipText.setValue(event.getCalendarItem().getTitle() + "-" + event.getCalendarItem().getContent());
    }

CalendarsEvent.ON_WEEK_CLICK

Calendars fires this event when you click the week number of the year on the left-hand side when you set weekOfYear=”true”.

An Event object is passed to your event listener.

CalendarsEvent.ON_DAY_CLICK

Calendars fires this event when you click when a user clicks on the date texts (TUE 10/3) on the top of the component.

It passes an Event object, not CalendarsEvent, to your event listener, and you can get the clicked date:

public class EventComposer extends SelectorComposer<Component> {
...
    @Listen(CalendarsEvent.ON_DAY_CLICK + "=calendars")
    public void handleDayClick(Event event){
        Date clickedDate = (Date) event.getData();
    }

CalendarsEvent

ZK will call your event listener method with an org.zkoss.calendar.event.CalendarsEvent as a parameter when one of the ON_ITEM_* events is triggered. So you should declare your method signature like:

    @Listen(CalendarsEvent.ON_ITEM_CREATE + " = #calendars")
    public void showCreationBox(CalendarsEvent event) {...}

Then you can call getBeginDate(), getEndDate(),or getCalendarItem() to implement your application logic. Please refer to javadoc for complete methods and their details.