Implementing Event Listeners"

From Documentation
m (replace tt with code (via JWB))
Line 28: Line 28:
 
Event name in 2.1: [https://www.zkoss.org/javadoc/zkcal/2.1.5/org/zkoss/calendar/event/CalendarsEvent.html#ON_EVENT_EDIT <code>ON_EVENT_EDIT(onEventEdit)</code>]
 
Event name in 2.1: [https://www.zkoss.org/javadoc/zkcal/2.1.5/org/zkoss/calendar/event/CalendarsEvent.html#ON_EVENT_EDIT <code>ON_EVENT_EDIT(onEventEdit)</code>]
  
==[https://www.zkoss.org/javadoc/latest/zkcal/org/zkoss/calendar/event/CalendarsEvent.html#ON_ITEM_UPDATE <code>CalendarsEvent.ON_ITEM_UPDATE</code>] ==
+
==[https://www.zkoss.org/javadoc/latest/zkcal/org/zkoss/calendar/event/CalendarsEvent.html#ON_ITEM_UPDATE 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.
 
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.
  
Line 36: Line 36:
  
 
Event name in 2.1: [https://www.zkoss.org/javadoc/zkcal/2.1.5/org/zkoss/calendar/event/CalendarsEvent.html#ON_EVENT_UPDATE <code>ON_EVENT_UPDATE(onEventUpdate)</code>]
 
Event name in 2.1: [https://www.zkoss.org/javadoc/zkcal/2.1.5/org/zkoss/calendar/event/CalendarsEvent.html#ON_EVENT_UPDATE <code>ON_EVENT_UPDATE(onEventUpdate)</code>]
 +
 +
== [https://www.zkoss.org/javadoc/latest/zkcal/org/zkoss/calendar/event/CalendarsEvent.html#ON_ITEM_TOOLTIP 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.
 +
 +
[[File:onitemtooltip.jpg | center]]
 +
 +
<syntaxhighlight lang='java'>
 +
    @Listen(CalendarsEvent.ON_ITEM_TOOLTIP +"= calendars")
 +
    public void showTooltip(CalendarsEvent event) {
 +
        tooltipText.setValue(event.getCalendarItem().getTitle() + "-" + event.getCalendarItem().getContent());
 +
    }
 +
</syntaxhighlight>
  
 
= CalendarsEvent =
 
= CalendarsEvent =

Revision as of 09:10, 6 March 2023


DocumentationZK Calendar EssentialsImplementing Event Listeners
Implementing Event Listeners





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

Since 3.0.0

The ZK Calendar will fire events below:

Icon info.png Notice: Event names change since version 3.0.0

CalendarsEvent.ON_ITEM_CREATE

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

Onitemcreate.gif

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.

Onitemedit.gif

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.

Onitemupdate.gif
Onitemupdate2.gif

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.

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

CalendarsEvent

ZK will call your event listener method with an CalendarsEvent as a parameter when one of the supported 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.



The example project is at Github


Last Update : 2023/03/06

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.