Wednesday 11 April 2018

Event Handler and Event Listener

Event Handler:: The sling level events can be captured by implementing the event handler interface. A property called EventConstants.EVENT_TOPIC has to be fined which signifies what event has to be captured. In this case the event handler catches the page being created. handleEvent(Event event)  method is implemented which can have the code to implement the business logic. Like we cna set a new property on creation of a page
 Example::
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "=Your Description here",
EventConstants.EVENT_TOPIC + "=com/day/cq/wcm/core/page" })

Event Listener:: The event handling at the jcr level can be captured by implementing the event listener interface. It is mostly concerned about the low level jcr events like node or property movement, addition, deletion etc.  The onEvent(EventIterator events) can be used to include the business logic, like deleting some property on node being copied. Observation manager can be used is used to listen to listen to events like Event.NODE_ADDED.

Example:: observationManager.addEventListener(this, Event.NODE_ADDED, path, true, null, null, false); :: In this example the event listener listens to the node being added to the jcr repository.


No comments:

Post a Comment

extraClientlibs Usage

The purpose of property "extraClientlibs" is to selectively load client library for a dialog. This prevents the unnecessary load o...