Hi Cecile, On Nov 9, 2012, at 8:02 AM, Cecile <cecile.florentin@dcnsgroup.com> wrote:
Hello everyone,
I'm trying to write a listener. The listener is correctly triggered after creation. But when I change the listener code, it is not taken into account by the server. I have to
restart the server. How to avoid this?
This my code:
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import com.xpn.xwiki.*
class AutoEventListener implements EventListener { def xwiki def context
AutoEventListener(xwiki, context) { this.xwiki = xwiki this.context = context }
String getName() { return "auto_febi" }
List<Event> getEvents() { return Arrays.asList(new DocumentSaveEvent()) }
void onEvent(Event event, Object source, Object data)
{
if (source.fullName != "EventListenerAuto") {
This will not work since fullName is of the format Space.Page so it'll never match...
def document = xwiki.getDocument(source.fullName)
This is not needed since you're passed the XWikiDocument already in the source… ;)
def var= document.getValue("avisDSI")
Thus you can write directly: source.getValue("avisDSI")
if (var != "-"){ document.set("nomDSI","coucou")}
same: source.set(….) Now you're missing a source.save(…) to save the change here!
} } }
def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("auto_febi") def listener = new AutoEventListener(xwiki, xcontext) observation.addListener(listener)
Hope it helps, -Vincent
{{/groovy}}
Thank you very much for your future answer,
Cécile