Changes for page Writing an Event Listener

Last modified by Simon Urli on 2023/10/10

From version 4.1
edited by Marius Dumitru Florea
on 2014/05/30
Change comment: Event listeners should not keep a reference to the XWiki Context from when they were created!
To version 5.1
edited by Danilo Oliveira
on 2014/05/30
Change comment: There is no comment for this version

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.mflorea
1 +XWiki.DaniloOliveira
Content
... ... @@ -1,8 +1,11 @@
1 -{{box cssClass="floatinginfobox" title="**Contents**"}}{{toc/}}{{/box}}
1 +{{box cssClass="floatinginfobox" title="**Contents**"}}
2 +{{toc/}}
3 +{{/box}}
2 2  
3 3  XWiki supports notifications (a.k.a Observation Events) and it's possible to do some action when a document is modified, when a document's objects are modified, when a wiki is created, etc. See the full documentation in the [[Observation reference documentation>>extensions:Extension.Observation Module]].
4 4  
5 5  There are several ways to write an Event Listener to react to some events:
8 +
6 6  * In Java, as an [[XWiki Component>>extensions:Extension.Component Module]]
7 7  * In a wiki page, as a [[Wiki Component>>extensions:Extension.WikiComponent Module]]
8 8  * In a wiki page, using Groovy, by writing an XWiki Component and manually registering it against the Component Manager
... ... @@ -20,6 +20,7 @@
20 20  {{/warning}}
21 21  
22 22  Follow these steps:
26 +
23 23  * Create a page, for example ##EventListeners.DocumentSaveListener##
24 24  * Add a ##XWiki.ComponentClass## XObject in it
25 25  ** Component Role Type: ##org.xwiki.observation.EventListener##
... ... @@ -56,7 +56,8 @@
56 56  if (docSource.space != "EventListeners") {
57 57   docSource.setContent(docSource.content + "\n\nSome extra content...")
58 58  }
59 -{{/groovy}}{{/code}}
63 +{{/groovy}}
64 +{{/code}}
60 60  )))
61 61  * Save!
62 62  
... ... @@ -226,6 +226,11 @@
226 226  )))
227 227  * Build the project with maven: ##mvn clean install## and copy the JAR generated in the ##target## directory in your XWiki's ##WEB-INF/lib## directory, and restart XWiki.
228 228  
234 +{{info}}
235 +If you are experiencing problems trying to build it, see:
236 +http://dev.xwiki.org/xwiki/bin/view/Community/Building
237 +{{/info}}
238 +
229 229  Before trying it, go to your wiki's administration page and make sure you've configured the Email properties. Try it by adding a new comment on a page. You should receive an email!
230 230  
231 231  {{warning}}
... ... @@ -235,4 +235,3 @@
235 235  = Old Notifications Tutorial =
236 236  
237 237  If you're using an old version of XWiki (prior to 2.0) you should check this [[old Notifications Tutorial>>GroovyNotificationTutorial]].
238 -

Get Connected