Solved! Go to Solution.
Views
Replies
Total Likes
@Mario248 : Every template has a resource type, I believe you can make use of that instead of template name. Also, you can use this in combination with path as well.
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "=Event Handler ",
EventConstants.EVENT_TOPIC + "="+ReplicationAction.Event_Topic,
EventConstants.EVENT_FILTER + "= ((path=/content/your-site/*)(resourceType=myapp/components/page/your-page-component))" })
You can refer this :- https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/event-filter-is-not-workin...
https://techagyan.blogspot.com/2015/02/aem-event-handling-and-filtering.html
thanks.
Hi @Mario248
You can use ResourceChangeListener class to handle sling level events and below is the sample code and you can customize it according to your business logic.
import org.apache.sling.api.resource.observation.ResourceChange;
import org.apache.sling.api.resource.observation.ResourceChangeListener;
import org.osgi.service.component.annotations.Component;
@Component(service = ResourceChangeListener.class,
property = {
"sling.resourceType=/conf/abc/temp1", // Target the specific template
"path=/content/(.*)" // Observe page creation under content
})
public class PageCreationEventHandler implements ResourceChangeListener {
@Override
public void onChange(ResourceChange change) {
if (change.getType() == ResourceChange.Type.ADDED) {
// Page has been created
String pagePath = change.getPath();
// Your custom logic here
System.out.println("Page created: " + pagePath);
// Example: Send a notification, perform additional processing, etc.
}
}
}
Hope it helps.
Thanks for your response. You are using ResourceChangeListener over sling events. Is there any preference and suggestion?
The ResourceChangeListener is the recommended approach, as sending all repository changes as OSGI events is not scalable enough. Also you need to handle all requests, you cannot limit your listener be called only for a certain path(s).
Views
Replies
Total Likes
@Mario248 : Every template has a resource type, I believe you can make use of that instead of template name. Also, you can use this in combination with path as well.
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "=Event Handler ",
EventConstants.EVENT_TOPIC + "="+ReplicationAction.Event_Topic,
EventConstants.EVENT_FILTER + "= ((path=/content/your-site/*)(resourceType=myapp/components/page/your-page-component))" })
You can refer this :- https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/event-filter-is-not-workin...
https://techagyan.blogspot.com/2015/02/aem-event-handling-and-filtering.html
thanks.
Thank for your reply. For some reason the sling resource type is common for other pages hence I have to reply on cq:template property hence I tried below code but it is not working. any reason ?
@Component(service = EventHandler.class, immediate = true, property = {
Constants.SERVICE_DESCRIPTION + "=Event Handler ",
EventConstants.EVENT_TOPIC + "="+ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "= ((cq:template=/conf/abc/template))" })
@Mario248 : In that case, you will have to create an EventHandler at a path level to reduce triggering of it everywhere and then in handleEvent method you can apply the filter based on cq:template property.
@Override
public void handleEvent(Event event) {
ReplicationAction replicationAction = ReplicationAction.fromEvent(event);
String pagePath = replicationAction.getPath();
//read the jcr:content/cq:template property value and check if it matches with your template. based on the match you can take action.
}
Thank, But this particular service is triggered for all the pages and we are checking and filtering based on cq:template which is kind of okay but this service/component gets fired for all aem pages. Is there any filter which we can apply before this stage?
Views
Likes
Replies
Views
Likes
Replies