Hello All,
I have CustomEventHandler class which implements EventHandler interface.
handleEvent method is called during page activation, deactivation, deletion time. Here, I need to mention the page path. I mean if a page is present under /content/abc/project/en then only my custom event handler should trigger. I need to mention multiple page path. /content/abc/project/en, /content/xyz/project/en
Any help in this?
Solved! Go to Solution.
Views
Replies
Total Likes
here you go
|(paths=/content/abc/myArticle/*)(paths=/content/abc/newArticle/*)
Please check this thread
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/multiple-paths-handling-in...
Regards,
Divanshu
Hi @Mahesh_Gunaje
Could you please check https://lucanerlich.com/docs/aem/event-listener/
Preferably use ResourceChangeListener
It will also allow you to use multiple paths
https://techrevel.blog/2017/03/15/resourcechangelistener/
ResourceChangeListener logic sounds interesting. But in my case, if I use implements EventHandler, then I can write my logic for
if ReplicationActionType.ACTIVATE : call add customMethod();
if ReplicationActionType.DEACTIVATE : call customDelete Method
if ReplicationActionType.DELETE: call customDelete Method
So, How can I call my method if i implement ResourceChangeListener.
I can see only one method.
Hello @Mahesh_Gunaje
Please refer to this blog https://aemhints.com/2020/11/08/event-listener-in-aem-6-5/
It uses Event Handler with multiple Paths.
I have tried the logic mentioned in that link. Still, handleEvent() method is called for other page Path as well.
I have found the solution here: https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-event-filter-not-worki...
In this, @dishi_k mentioned about
EventConstants.EVENT_FILTER + "=(paths=/var/...somepath/*)"
This was working for me. So, now my class looks like:
@Component(service = EventHandler.class,
immediate = true,
property = {
EventConstants.EVENT_FILTER + "=(paths=/content/abc/myArticle/*)",
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
})
public class customEventHandler implements EventHandler {
}
So that if I publish any page under other path: /content/abc/newArticles/* my customEventHandler class is not at all called.
Now, my next task is to 1: mention regular expression instead of /content/abc/myArticle/* Or else 2: need to pass the path from OSGI config.
Hi @Mahesh_Gunaje
For path expressions you can check sample code at https://github.com/arunpatidar02/aemaacs-aemlab/blob/master/core/src/main/java/com/community/aemlab/...
Hi @arunpatidar
Checked your code. Still have confusion.
As of now, I have used: EventConstants.EVENT_FILTER + "=(paths=/content/abc/myArticle/*)"
Now, how to mention 2 paths here:
/content/abc/myArticle/*
/content/abc/newArticle/*
Since, your code has: EventConstants.EVENT_FILTER + "(&" + "(path=/content/we-retail/us/en/*/jcr:content) (|("
+ SlingConstants.PROPERTY_CHANGED_ATTRIBUTES + "=*jcr:title) " + "(" + ResourceChangeListener.CHANGES
+ "=*jcr:title)))" })
here you go
|(paths=/content/abc/myArticle/*)(paths=/content/abc/newArticle/*)
Hi @arunpatidar
Works like a charm. Thanks a lot Arun
@Component(service = EventHandler.class,
immediate = true,
property = {
EventConstants.EVENT_FILTER + "=(|(paths=/content/abc/myArticle/*)(paths=/content/abc/newArticle/en/*))",
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
})
public class customEventHandler implements EventHandler { ... }