3 Replies Latest reply on Mar 22, 2012 10:26 AM by nicolas peltier

    EventHandler for my own Events

    Luthiger

      How can I make an EventHandler listening to only my own Events?

      I have the following EventHandler implementation:

      === Java class ===

      @Component(immediate = true, metatype = false)

      @Service

      @Property(name = EventConstants.EVENT_TOPIC, value = MyProcessor.EVENT_TOPIC)

      public class MyProcessor implements EventHandler {

          public static final String EVENT_TOPIC = "my/event/handling";

       

       

          /*

           * (non-Javadoc) org.apache.sling.event.EventUtil

           *

           * @see org.osgi.service.event.EventHandler#handleEvent(org.osgi.service.event.Event)

           */

          @Override

          public void handleEvent(final Event inEvent) {

              // do event handling

          }

      }

      ===

       

      But what information do I have to provide in my component's cd:EditConfig to make the system sending the appropriate Event my event handler class is listening to?

      ===

      <?xml version="1.0" encoding="UTF-8"?>

      <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

          cq:dialogMode="floating"

          jcr:primaryType="cq:EditConfig">

          <cq:listeners

              jcr:primaryType="cq:EditListenersConfig"

              beforeinsert="myAction"

              />

      </jcr:root>

      ===

      What value do I have to provide for the beforinsert action (in this example) to trigger the event handles by my handler?

       

      Regards,

      Benno

        • 1. Re: EventHandler for my own Events
          nicolas peltier Adobe Employee

          Hi,

           

          1 the handler is a sling event handler  (server side)

          2 the beforeinsert stuff is about Ext-JS event (client side)

           

          so there is now way 1 catch 2.

           

          what are you trying to do?

          1 person found this helpful
          • 2. Re: EventHandler for my own Events
            Luthiger Level 1

            Dear Nicolas

             

            Thanks for your quick answer.

            > the beforeinsert stuff is about Ext-JS event (client side)

            I have not been aware of that, thanks a lot.

             

            My use case is that I have to add a specific parent node to the node I'm about to insert.

             

            Just out of curiosity:

            How does the system propagate events like page refresh to server side event handlers registered for

            PageEvent.EVENT_TOPIC = "com/day/cq/wcm/core/page"?

            ===

            <?xml version="1.0" encoding="UTF-8"?>

            <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

                cq:dialogMode="floating"

                jcr:primaryType="cq:EditConfig">

                <cq:listeners

                    jcr:primaryType="cq:EditListenersConfig"

                    aftercreate="REFRESH_PAGE"

                    />

            </jcr:root>

            ===

             

            Regards

            Benno

            • 3. Re: EventHandler for my own Events
              nicolas peltier Adobe Employee

              Don't understand "I have to add a specific parent node to the node I'm about to insert." you should have a parent to insert a node at first, right?

               

              Anyway, you could post the parent, and then the child (or both at the same time) using SlingPostServlet

               

              as in my previous answer, the first one never hear about the second one...(1=server, 2=js) 1:is for server side handlers, 2 is a client side handler (the REFRESH_PAGE action is done after the ExtJS event  aftercreate is fired)