Event Handling

Event Listeners

Event listeners provide FM-Classic a way of notifying your code whenever interesting events happen during the processing of a template. Event listeners are a new, optional feature of FM-Classic. If you decide not to use them, FM-Classic will continue to work using legacy FreeMarker behaviour.

To register your code to receive FM-Classic events, construct a new TemplateEventAdapter and register your template listener objects with this adapter. Many listeners may be registered to listen for the same events, as TemplateEventAdapter implements the standard multicast event pattern. When the template is processed, simply pass your TemplateEventAdapter as a parameter into the process() method of your Template object, along with your root template model and Writer.

Currently, only one type of event can be generated by FM-Classic: a TemplateExceptionEvent. More event types may be added to FM-Classic in future releases.