On Wed, May 21, 2014 at 1:36 PM, walid yaich <[email protected]> wrote: > Thank you, > > But i really cannot get it work, >>>As I said, you need to modiy the document comming with the event (the >>>fist parameter). That's the one that is going to be saved right after > is it right like that ? : > void onEvent(Event event, Object source, Object data) > { > def currentDocument = xwiki.getDocument(source.fullName)
Why are you calling getDocument ? source is already a XWikiDocument instance. I will say it again: you need to modify source itself because that's what is going to be saved, not some instance you kept from when you registered the listener, not a new instance, source. If you don't know the API of XWikiDocument you can look at http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org/xwiki/platform/xwiki-platform-oldcore/5.4.4/xwiki-platform-oldcore-5.4.4-javadoc.jar/!/index.html (modify the link according to your version). > currentDocument.newObject("RevisionSpace.RevisionClass") > //currentDocument.save() //When saving, i got a stackoverflow > //XWikiDocument currentDocument = (XWikiDocument) source > //Cannot cast from XWikiDocument to Document > } > This code does not save the object, something wrong with it ? > > I tried just this : > {{groovy}} > doc.newObject("RevisionSpace.RevisionClass") > doc.save() > println "{{info}} Object added {{/info}}" > {{/groovy}} > it creates two objects in the current page, any explanation ? > > I'm using Admin/admin and XWIKI entreprise 6.0, some way to debug to know > why it doesn't save ? > > Thanks in advance > > > > 2014-05-21 8:39 GMT+01:00 Thomas Mortagne <[email protected]>: > >> On Tue, May 20, 2014 at 9:21 PM, walid yaich <[email protected]> >> wrote: >> > Good morning :) >> > >> > I added a listener on DocumentCreatingEvent, this listener will add an >> > object of type RevisionClass to every new document. (RevisionClass is >> under >> > RevisionSpace) >> > In onEvent i have doc.newObject("XWiki.RevisionClass"), i'm sure onEvent >> is >> >> As I said, you need to modiy the document comming with the event (the >> fist parameter). That's the one that is going to be saved right after >> the event (so just add the object and don't save it yourself), >> whatever you save in your code is going to be overwritten after it. >> >> > executed but when creating a new document, i can't find the object >> created >> > when doing edit-->object, in addition doc.newObject("blablabla") is >> > accepted and doesn't throw any exception. >> > >> > I'm using the default Admin/admin user, should i execute the script in a >> > specific space or with specific rights ? >> > Nothing is displayed in my console, How can i make XWIKI tell me more >> about >> > what it is doing ? >> > >> > I'm using Entreprise 6.0, would you please take a look at the attached >> > script ? >> > >> > >> > Best Regards, >> > Walid YAICH >> > >> > >> > >> > 2014-05-20 13:24 GMT+01:00 Jeremie BOUSQUET <[email protected] >> >: >> > >> >> 2014-05-20 13:38 GMT+02:00 walid yaich <[email protected]>: >> >> >> >> > Thanks, >> >> > >> >> > I prefer the listener, because i don't want the user to edit the >> object, >> >> > the object revision will be set by admin when he/she push "approve" to >> >> set >> >> > the revision to show by default. >> >> > >> >> > The listener works fine now, but i can't find how to add an object to >> a >> >> > page in groovy, i want to this in groovy : #set($obj = $doc.newObject( >> >> > "XWiki.SomeClass")) , a helpful link as always please ? >> >> > >> >> > >> >> Hi, >> >> Groovy has the same default bindings as velocity, so you could write: >> >> >> >> def obj = doc.newObject("XWiki.SomeClass") >> >> >> >> >> >> > >> >> > >> >> > >> >> > >> >> > 2014-05-20 10:44 GMT+01:00 [email protected] <[email protected]>: >> >> > >> >> > > Hi Walid, >> >> > > >> >> > > Maybe this could help: >> >> > > >> >> > > >> >> > >> >> >> http://www.xwiki.org/xwiki/bin/view/FAQ/How+can+I+create+a+new+page+based+on+a+form >> >> > > >> >> > > If your users use this form to create pages, the pages they create >> will >> >> > > automatically have the proper XObjects added to them and they’ll >> >> directed >> >> > > in inline mode when creating the page, allowing them to fill the >> >> XObject >> >> > > data. >> >> > > >> >> > > Thanks >> >> > > -Vincent >> >> > > >> >> > > On 19 May 2014 at 22:16:01, walid yaich ([email protected]) >> wrote: >> >> > > >> >> > > Hello, >> >> > > >> >> > > First of all, Merci bcp Vincent for this How to implement "Approved >> >> > > Revisions"?< >> >> > > >> >> > >> >> >> http://www.xwiki.org/xwiki/bin/view/FAQ/How+to+implement+%22Approved+Revisions%22 >> >> > > >> >> > > >> >> > > >> >> > > >> >> > > I was able to choose which revision to display by following the "how >> >> to", >> >> > > now i need to add the object automatically to any page in my wiki >> or at >> >> > > least any page in a given space >> >> > > >> >> > > Thanks in advance :) >> >> > > >> >> > > >> >> > _______________________________________________ >> >> > devs mailing list >> >> > [email protected] >> >> > http://lists.xwiki.org/mailman/listinfo/devs >> >> > >> >> _______________________________________________ >> >> devs mailing list >> >> [email protected] >> >> http://lists.xwiki.org/mailman/listinfo/devs >> >> >> > >> > _______________________________________________ >> > devs mailing list >> > [email protected] >> > http://lists.xwiki.org/mailman/listinfo/devs >> > >> >> >> >> -- >> Thomas Mortagne >> _______________________________________________ >> devs mailing list >> [email protected] >> http://lists.xwiki.org/mailman/listinfo/devs >> > _______________________________________________ > devs mailing list > [email protected] > http://lists.xwiki.org/mailman/listinfo/devs -- Thomas Mortagne _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs

