Hi,
My requirement is whenever i create a new page CQ has to add the new property.
so i prefered Even handlers and followed the below code.
The problem is i dont know weather the code is running?
i have checked the console i didn't get any log as well.
could anyone please help me and explain how event handlers running in CQ?
@Component public class ExampleObservation implements EventListener { Logger log = LoggerFactory.getLogger(this.getClass()); private Session adminSession; @Reference SlingRepository repository; @Activate public void activate(ComponentContext context) throws Exception { log.info("activating ExampleObservation"); try { adminSession = repository.loginAdministrative(null); adminSession.getWorkspace().getObservationManager().addEventListener(
this, //handler
Event.PROPERTY_ADDED|Event.NODE_ADDED, //binary combination of event types
"/content/", //path
true, //is Deep?
null, //uuids filter
null, //nodetypes filter false); } catch (RepositoryException e){ log.error("unable to register session",e); throw new Exception(e); } }
@Deactivate public void deactivate(){ if (adminSession != null){ adminSession.logout(); } } public void onEvent(EventIterator eventIterator) { try { while (eventIterator.hasNext()){
log.info("something has been added : {}", eventIterator.nextEvent().getPath());
} } catch(RepositoryException e){ log.error("Error while treating events",e); } } }
Solved! Go to Solution.
Michael,
if you just want to add a default property to a page when it's created, you can also just add it to the template node. Feike wrote a blog post [1], which shows how you can add default components to a page. But this approach works also if you just want to add a single default property.
Jörg
In your OSGi bunlde -- you should not be using
adminSession = repository.loginAdministrative(null);
to create a Session.
The preferred way is to inject a Sling ResourceResolverFactory:
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
//Queries the AEM JCR for customer data and returns
//the data within an XML schema
public String getCustomerData(String filter) {
Customer cust = null;
List<Customer> custList = new ArrayList<Customer>();
try {
//Invoke the adaptTo method to create a Session used to create a QueryManager
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
To learn how to use this code- see:
http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html
2nd -- are you referring to an online doc to learn how to use Event hanlders for AEM in an OSGi bundle? If so - can you provide the URL?
If you navigate to http://localhost:4502/system/console/components - do a find on the page for "ExampleObservation" and you should see it listed.
Please see the attached image for reference.
Hi Lee,
Thanks a lot for ur quick response.
Regards,
Mike
Views
Replies
Total Likes
Michael,
if you just want to add a default property to a page when it's created, you can also just add it to the template node. Feike wrote a blog post [1], which shows how you can add default components to a page. But this approach works also if you just want to add a single default property.
Jörg
Hi Scott,
Thanks for your replay.
i have refered the below Site.
http://experiencedelivers.adobe.com/cemblog/en/experiencedelivers/2012/04/event_handling_incq.html
Regards,
Mike
Views
Replies
Total Likes
Hi Jorg,
Thanks a lot for your reply. its really helpful for me.
Regards,
Mike
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies