2

How can I add an event handler for my Adobe AEM6 component that triggers when a child component is deleted?

There are several listeners that I can attach event handlers to, listed in the documentation for cq:listeners but unfortunately there isn't one for afterchilddelete.

I've tried adding a cq:childEditConfig node to the component but, at least in AEM6, the handler doesn't fire:

<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:EditConfig">
    <cq:listeners
        jcr:primaryType="cq:EditListenersConfig"
        afterdelete="mynamespace.afterchilddelete"/>
</jcr:root>
Alasdair McLeay
  • 2,572
  • 4
  • 27
  • 50
  • 2
    What does your handler do? Does it have to be on the client? An alternative would be an javax.jcr.observation.EventListener in your Java code. – Thomas Aug 04 '14 at 10:46
  • I want to rerender the parent component, client side, when a child component is deleted, as an 'empty' component looks different to one with child components – Alasdair McLeay Aug 06 '14 at 08:57
  • Have you tried to add the afterdelete listener to the child components editConfig? Maybe you'll need to use the beforedelete if you need a reference to the deleted child. Or even a refresh the whole page to be sure the parent renders correctly. – Thomas Aug 06 '14 at 11:28
  • unfortunately the child component can be any component, so I would have to add an afterdelete listener for every component in the site – Alasdair McLeay Aug 06 '14 at 12:42
  • ok, that is a valid point. Maybe you could use something out of AEm, like: http://stackoverflow.com/questions/2200494/jquery-trigger-event-when-an-element-is-removed-from-the-dom – Thomas Aug 06 '14 at 12:45

0 Answers0