How to invalidate a document from an event listener

Hi,

I have a listener class that implements org.nuxeo.ecm.core.event.EventListener, and I want to invalidate the current document from there. Normally, in a bean, I use to inject NavigationContext, and then use its method to invalidate the document. But I don't know how can I inject NavigationContext to a listener (if it is possible), and I don't know if there is another way to invalidate the current document from there too.

Also, is there a way to inject a bean to a listener? Because that would also work for me.

Thank you very much in advance,

0 votes

1 answers

2098 views

ANSWER



Hi, You can access EventContext, CoreSession, SourceDocument from DocumentEventContext where event is fired ( you can control process of firing event ), but not Navigation Context as listener is executed on background can't access navigation context. You also can get Services instances on listener, as for example Framework.getService(serviceClass), you can contribute your custom services (with your business logic) or use Document Adapter. Thanks

1 votes



Thanks Saimir,

so does that mean that there is no way to invalidate the document from a listener?

06/08/2017

from listener you can do what you want with document ( invalidate, change life cycle, update properties and sure you can delete it ) all things that you can do in operation chain/seam bean you can do in event listener. It's important to chose right event witch depends on your business. Form more details you can check nuxeo docs https://doc.nuxeo.com/nxdoc/events-and-listeners/
06/08/2017