EventListener DocumentRenamingEvent not working

Hi.
I’m trying to set up an Event Listener on the DocumentRenamingEvent as Wiki Component and can not make it work.
I followed the Tutorial for Writing an Event Listener and my test works when I’m listening to DocumentCreatingEvent, DocumentUpdatingEvent or DocumentDeletingEvent, but not for DocumentRenamingEvent. I’ve tried DocumentRenamedEvent, EntitiesRenamedEvent, DocumentCopiedEvent and DocumentCopyingEvent, too and it doesn’t work either.

My getEvents Method looks like this:

{{groovy}}
import org.xwiki.bridge.event.*
xcontext.method.output.value = [new DocumentRenamingEvent()]
{{/groovy}}

onEvent:

{{groovy}}
def Testpage = xwiki.getDocument("MyTestPage.Child1.WebHome")
    Testpage.setContent("thisisatest")
    Testpage.save("testSaveOnRenaming", true)
{{/groovy}}

Any idea what I’m doing wrong?

2 Likes

Anyone an idea?

Regards Simpel

You might want to look at https://extensions.xwiki.org/xwiki/bin/view/Extension/Script%20Component/ which makes it much easier to implement and debug components implemented in wiki pages. It’s also much better for performances.

As my primary problem needing this event listener is solved (How to prevent internal wiki links as url) I will not check your suggestion anymore.

Nevertheless thank you, Simpel

Ran into this issue again, with DocumentRenamedEvent. The event doesn’t fire at all, even if the listener is loaded correctly. When listening for DocumentUpdatedEvent or XObjectUpdatedEvent, it works.

If this is a bug, I think it might have something to do with DocumentRenamedEvent and DocumentRenamingEvent being part of the org.xwiki.refactoring.event package, while most other events are part of com.xpn.xwiki.internal.event or org.xwiki.bridge.event. Maybe the groovy macro is missing some import paths or something along those lines?

Edit: It also seems like the last argument to onEvent (which is supposed to be the context) is always null, no matter what event I listen to. I don’t know what that is about, or if it is related

Tried with the Script Components but I couldn’t get them to work at all, mistake on my part.

I’m not sure what you mean. There are no default imports in the Groovy macro, you have to import everything you use.

When there is something wrong with your script, you generally get a detailed error in the server log.

1 Like