[xwiki-devs] listener not reloading after modification
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") { def document = xwiki.getDocument(source.fullName) def var= document.getValue("avisDSI") if (var != "-"){ document.set("nomDSI","coucou")} } } } def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("auto_febi") def listener = new AutoEventListener(xwiki, xcontext) observation.addListener(listener) {{/groovy}} Thank you very much for your future answer, Cécile -- View this message in context: http://xwiki.475771.n2.nabble.com/listener-not-reloading-after-modification-... Sent from the XWiki- Dev mailing list archive at Nabble.com.
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
Hi, I'm working with Cecile who is away this week. Thanks for the correction of the listener code but our main problem is that any update of the code isn't taken in account by the listener, except after restarting the XWiki platform. No way to do it without this restart ? Thanks Patrice -- View this message in context: http://xwiki.475771.n2.nabble.com/listener-not-reloading-after-modification-... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hello, We finally solved our problem by using the button "Register Event Listener" described here : http://platform.xwiki.org/xwiki/bin/download/DevGuide/GroovyNotificationTuto... RTFM ! Patrice -- View this message in context: http://xwiki.475771.n2.nabble.com/listener-not-reloading-after-modification-... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hi Patrice, Just for the record, know what with recent version of XE you can use wiki components to do this, see: http://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent+Module That's the new best way of registering event listeners in wiki page. Note that this is not really recommended except maybe for quick proof of concepts; the best solution is to write the listeners in Java, see http://platform.xwiki.org/xwiki/bin/view/DevGuide/BestPractices#HWheretoputc... Thanks -Vincent On Nov 15, 2012, at 6:23 PM, Patrice <patrice.premel@dcnsgroup.com> wrote:
Hello,
We finally solved our problem by using the button "Register Event Listener" described here : http://platform.xwiki.org/xwiki/bin/download/DevGuide/GroovyNotificationTuto...
RTFM !
Patrice
participants (4)
-
Cecile -
Cecile FLORENTIN -
Patrice -
Vincent Massol