Hi,
I’ve written an extension that wants to listen for the renaming of pages but for some reason the onEvent
method is not being called.
I followed the “Writing an EventListener Tutorial” for a Java component. After that didn’t appear to work, I noticed that the code in the Tutorial is “Before 5.4” according to the Local Observation Module document so I switched to the example for “Since 5.4”, using the abstract class that’s provided. However, this did not fix the issue either.
I made my component Initializable and my initialize method is being called when the extension is installed via the Extension Manager so that would suggest (at least to me ) that XWiki is recognising it as a valid component.
I’ve also installed the Event Listener Administration Application/Extension which does list my class as an event listener and for the right events.
Below is the simplest component I could put together. It’s listed in the Event Listener Administration app for the DocumentRenamingEvent
and DocumentRenamedEvent
events (so I think the components.txt
file is correct).
It logs at error just to make as sure as I can that I’ll see the output in the logs.
package dev.seekingbinary.xwiki.events;
import javax.inject.Inject;
import javax.inject.Named;
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
import org.xwiki.observation.AbstractEventListener;
import org.xwiki.observation.event.Event;
import org.xwiki.refactoring.event.DocumentRenamedEvent;
import org.xwiki.refactoring.event.DocumentRenamingEvent;
@Component
@Named("alexeventlistener")
public class AlexEventListener extends AbstractEventListener implements Initializable {
@Inject
private Logger log;
public AlexEventListener() {
super("alexeventlistener", new DocumentRenamingEvent(), new DocumentRenamedEvent());
}
@Override
public void onEvent(Event event, Object source, Object data) {
log.error("onEvent");
}
@Override
public void initialize() throws InitializationException {
log.error("alex init");
}
}
With that all in place, I then:
- Navigate to a page.
- Click the ellipsis menu
- Click “Move / Rename”
- Enter a new Title
- Click Rename
- The page (and its URL) appear to be successfully renamed but, no events are received in my listener.
Any suggestions?
Thanks in advance,
Alex