Event Listener always catching Event.PROPERTY_ before Event.NODE_ Events | Community
Skip to main content
Level 4
January 15, 2025
Solved

Event Listener always catching Event.PROPERTY_ before Event.NODE_ Events

  • January 15, 2025
  • 3 replies
  • 664 views

Hi All,

When ever event is getting triggered -

EX - 

If i am doing operation Page move.

EventType is coming as = Event.PROPERTY_ADDED but it should check for as Event.NODE_MOVED. even though i am checking as a conditional statement it is always going to Event.PROPERTY (Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED) listener instead of  Event.NODE (Event.NODE_MOVED | Event.NODE_ADDED | Event.NODE_REMOVED listener.

 

Again, This is happing for Page Delete also.

 

Req - to Implement custom logic on each and every event Listener.

 

As we know whenever we trigger event on NODE AEM itself call's PROPERY events :::

Is there any way to identify the correct event or give precedence to NODE events instead of PROPERTY???

 

Using Event like this - 

private static final int EVENT_TYPES = Event.NODE_MOVED  | Event.NODE_ADDED | Event.NODE_REMOVED |
Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;

 

Thanks in advance.

 

 

Best answer by AmitVishwakarma

To prioritize NODE_* events over PROPERTY_* events in your AEM event listener:

  1. Check for Event.NODE_* events (like NODE_MOVED, NODE_ADDED, NODE_REMOVED) first in your listener logic.
  2. Process property events (like PROPERTY_ADDED, PROPERTY_CHANGED) only if no node event is found.
  3. Optionally, use separate listeners for node and property events to avoid conflicts.

Ensure the listener prioritizes node events by checking them first in your conditionals.

3 replies

arunpatidar
Community Advisor
Community Advisor
January 15, 2025

Hi @lone_ranger 

Could you please describe the use case here?

You are using JCR Events but there are other event types(Sling and OSGI) which can help.

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/clarification-eventlistener-eventhandler-and/td-p/608961 

 

Arun Patidar
joerghoh
Adobe Employee
Adobe Employee
January 17, 2025

When you want to work on page level, please check for the OSGI page events; they are sent alongside the resource events for that specific page.

 

And please be aware, that for delete the events can be unexpected;  for example if you delete a large subtree, you get the delete event only for the root-node/resource on which the delete was invoked.

AmitVishwakarma
Community Advisor
AmitVishwakarmaCommunity AdvisorAccepted solution
Community Advisor
January 19, 2025

To prioritize NODE_* events over PROPERTY_* events in your AEM event listener:

  1. Check for Event.NODE_* events (like NODE_MOVED, NODE_ADDED, NODE_REMOVED) first in your listener logic.
  2. Process property events (like PROPERTY_ADDED, PROPERTY_CHANGED) only if no node event is found.
  3. Optionally, use separate listeners for node and property events to avoid conflicts.

Ensure the listener prioritizes node events by checking them first in your conditionals.

Level 4
January 22, 2025

Thanks Amit