XWiki Standard 9.8.1 Documentation » Programming Overview » Post Processing Groovy Listener

Post Processing Groovy Listener

In the Groovy Notifications tutorial we have presented a way of logging the document create and update events using the XWiki Observation module. However, you might need to make some additional changes on the document after the "Save" action. 

A possible use case would be an XWiki application that stores resource names of any kind and for each application entry, the page title is identical to the page name. Supposing, you are already setting the title in the application sheet, you might also need the title to be automatically updated after renaming the entry. Moreover, you might want to avoid manual title changes from other users or even typos. For this purpose, you could create a Scheduler job named "Update Title Listener" with the following code:

import org.xwiki.observation.*
import org.xwiki.observation.event.*
import org.xwiki.bridge.event.*
import org.xwiki.observation.event.filter.*
import com.xpn.xwiki.web.*
import com.xpn.xwiki.*

class LoggingEventListener implements EventListener


  String getName()
     // The unique name of this event listener
     return "loggingTitle"

    List<Event> getEvents()
     // The list of events this listener listens to
    def regEx = new RegexEventFilter("xwiki:RessourcesApplication\\..*")
    return Arrays.asList(new DocumentCreatingEvent(regEx), new DocumentUpdatingEvent(regEx))

 // Called by the Observation Manager when an event matches the list of events returned
 // by getEvents()
void onEvent(Event event, Object source, Object data)
// Register against the Observation Manager
def observation = Utils.getComponent(ObservationManager.class)
def listener = new LoggingEventListener()

The events the listener listens to are:

and in order to be able to use them, you must make sure you have imported the dedicated package: import org.xwiki.bridge.event.*

The complete list of XWiki Bridge Events is available on GitHub. Another tutorial explaining how to update the value of the title field of an XWiki document based on the value of an object's property is available on xwiki.org.


Related Pages

Trying to decide between Cloud and On Premise? See the comparison on the XWiki Help Center.

Search this space