[xwiki-devs] Add an object by default for all pages
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 :)
I guess you can listen (http://extensions.xwiki.org/xwiki/bin/view/Extension/Observation+Module+Loca...) to org.xwiki.bridge.event.DocumentCreatingEvent event (xwiki-platform-bridge module) and add your object in the passed XWikiDocument. On Mon, May 19, 2014 at 10:15 PM, 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
-- Thomas Mortagne
Hi Walid, Maybe this could help: http://www.xwiki.org/xwiki/bin/view/FAQ/How+can+I+create+a+new+page+based+on... 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 :)
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 ? 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...
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 :)
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...
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+Revisio...
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
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 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...
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+Revisio...
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
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...
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+Revisio...
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
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) 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...
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+Revisio...
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
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... (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...
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+Revisio...
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
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;) I looked at the API and i find out that i should use this method: public int *createXObject*(EntityReference <http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/xwiki-commons-pom/xwiki-platform/xwiki-platform-core/xwiki-platform-model/apidocs/org/xwiki/model/reference/EntityReference.html?is-external=true> classReference, XWikiContext <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/%21/com/xpn/xwiki/XWikiContext.html> context) But i can't figure out how can i create an EntityReference object and How can i get the context from the actual event caller ? 2014-05-21 13:09 GMT+01:00 Thomas Mortagne <[email protected]>:
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... (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...
> > 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+Revisio...
> > > > > 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
On Wed, May 21, 2014 at 4:31 PM, walid yaich <[email protected]> wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference <http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/xwiki-commons-pom/xwiki-platform/xwiki-platform-core/xwiki-platform-model/apidocs/org/xwiki/model/reference/EntityReference.html?is-external=true> classReference, XWikiContext <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/%21/com/xpn/xwiki/XWikiContext.html> context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like: def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage") See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne <[email protected]>:
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... (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...
> > > > 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+Revisio...
> > > > > > > > > > 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
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
I finally got it ! Thanks guys :) This is my listener, it may help someone : {{velocity}} {{html}} #if ($request.confirm != "1") <form method="get"> <input type="hidden" name="confirm" value="1"/> <input type="submit" class="button" value="Register Event Listener"/> </form> #end {{/html}} {{/velocity}} {{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.* @Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { } String getName() { return "OnDocumentCreationEventListener" } List<Event> getEvents() { return Arrays.asList(new DocumentCreatingEvent()) } void onEvent(Event event, Object source, Object data) { log.info('onEvent begin') // Current context def crtContext = Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext') // A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass") source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully added !") log.info('onEvent end') } } // Only register the listener if the user has passed confirm=1 in the URL. This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}} It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added 2014-05-21 15:54 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 4:31 PM, walid yaich <[email protected]> wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference < http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext < http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne <[email protected]>:
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...
(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...
> > > > > > 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+Revisio...
> > > > > > > > > > > > > > > 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
_______________________________________________ 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
Hi Walid, What would be awesome is if you could contribute it on http://extensions.xwiki.org/xwiki/bin/view/Main/WebHome as a snippet :) Thanks -Vincent On 21 May 2014 at 18:43:30, walid yaich ([email protected](mailto:[email protected])) wrote:
I finally got it ! Thanks guys :)
This is my listener, it may help someone :
{{velocity}} {{html}} #if ($request.confirm != "1")
#end {{/html}} {{/velocity}}
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.*
@Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { }
String getName() { return "OnDocumentCreationEventListener" }
List getEvents() { return Arrays.asList(new DocumentCreatingEvent()) }
void onEvent(Event event, Object source, Object data) { log.info('onEvent begin')
// Current context def crtContext = Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext')
// A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass")
source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully added !")
log.info('onEvent end') } }
// Only register the listener if the user has passed confirm=1 in the URL. This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}}
It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added
2014-05-21 15:54 GMT+01:00 Thomas Mortagne :
On Wed, May 21, 2014 at 4:31 PM, walid yaich wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference < http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext < http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne :
On Wed, May 21, 2014 at 1:36 PM, walid yaich 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...
(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 > > >:
On Tue, May 20, 2014 at 9:21 PM, walid yaich 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 : >> >> > 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...
>> > > >> > > 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+Revisio...
>> > > >> > > >> > > >> > > >> > > 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
_______________________________________________ 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
With pleasure, i did it, here is the link : http://extensions.xwiki.org/xwiki/bin/view/Extension/Create+an+XObject+By+de... Please tell me if i can make it better 2014-05-21 17:45 GMT+01:00 [email protected] <[email protected]>:
Hi Walid,
What would be awesome is if you could contribute it on http://extensions.xwiki.org/xwiki/bin/view/Main/WebHome as a snippet :)
Thanks -Vincent
On 21 May 2014 at 18:43:30, walid yaich ([email protected](mailto: [email protected])) wrote:
I finally got it ! Thanks guys :)
This is my listener, it may help someone :
{{velocity}} {{html}} #if ($request.confirm != "1")
#end {{/html}} {{/velocity}}
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.*
@Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { }
String getName() { return "OnDocumentCreationEventListener" }
List getEvents()
{ return Arrays.asList(new DocumentCreatingEvent()) }
void onEvent(Event event, Object source, Object data) { log.info('onEvent begin')
// Current context def crtContext =
Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext')
// A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass")
source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully added !")
log.info('onEvent end') } }
// Only register the listener if the user has passed confirm=1 in the
URL.
This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}}
It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added
2014-05-21 15:54 GMT+01:00 Thomas Mortagne :
On Wed, May 21, 2014 at 4:31 PM, walid yaich wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better
;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference <
http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext <
http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne :
On Wed, May 21, 2014 at 1:36 PM, walid yaich 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...
(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 > > >:
> On Tue, May 20, 2014 at 9:21 PM, walid yaich > 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 :
> >> > >> > 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...
> >> > > > >> > > 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+Revisio...
> >> > > > >> > > > >> > > > >> > > > >> > > 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
_______________________________________________ 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
On 21 May 2014 at 21:24:39, walid yaich ([email protected](mailto:[email protected])) wrote:
With pleasure, i did it, here is the link : http://extensions.xwiki.org/xwiki/bin/view/Extension/Create+an+XObject+By+de...
Please tell me if i can make it better
This is great and nicely documented! Thanks a lot on behalf of all the future users who’ll thank you :) Thanks -Vincent
2014-05-21 17:45 GMT+01:00 [email protected] :
Hi Walid,
What would be awesome is if you could contribute it on http://extensions.xwiki.org/xwiki/bin/view/Main/WebHome as a snippet :)
Thanks -Vincent
On 21 May 2014 at 18:43:30, walid yaich ([email protected](mailto: [email protected])) wrote:
I finally got it ! Thanks guys :)
This is my listener, it may help someone :
{{velocity}} {{html}} #if ($request.confirm != "1")
#end {{/html}} {{/velocity}}
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.*
@Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { }
String getName() { return "OnDocumentCreationEventListener" }
List getEvents()
{ return Arrays.asList(new DocumentCreatingEvent()) }
void onEvent(Event event, Object source, Object data) { log.info('onEvent begin')
// Current context def crtContext =
Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext')
// A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass")
source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully added !")
log.info('onEvent end') } }
// Only register the listener if the user has passed confirm=1 in the
URL.
This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}}
It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added
2014-05-21 15:54 GMT+01:00 Thomas Mortagne :
On Wed, May 21, 2014 at 4:31 PM, walid yaich wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better
;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference <
http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext <
http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne :
On Wed, May 21, 2014 at 1:36 PM, walid yaich 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...
(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 > > >:
> >> On Tue, May 20, 2014 at 9:21 PM, walid yaich >> 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 :
>> >> >> >> > 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...
>> >> > > >> >> > > 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+Revisio...
>> >> > > >> >> > > >> >> > > >> >> > > >> >> > > 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 :) >> >> > >
On Wed, May 21, 2014 at 6:42 PM, walid yaich <[email protected]> wrote:
I finally got it ! Thanks guys :)
This is my listener, it may help someone :
{{velocity}} {{html}} #if ($request.confirm != "1") <form method="get"> <input type="hidden" name="confirm" value="1"/> <input type="submit" class="button" value="Register Event Listener"/> </form> #end {{/html}} {{/velocity}}
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.*
@Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { }
String getName() { return "OnDocumentCreationEventListener" }
List<Event> getEvents() { return Arrays.asList(new DocumentCreatingEvent()) }
void onEvent(Event event, Object source, Object data) { log.info('onEvent begin')
// Current context def crtContext = Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext')
As I said in the preview mail data is the XWikiContext.
// A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass")
source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully added !")
log.info('onEvent end') } }
// Only register the listener if the user has passed confirm=1 in the URL. This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}}
It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added
2014-05-21 15:54 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 4:31 PM, walid yaich <[email protected]> wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference < http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext < http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne <[email protected]>:
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...
(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...
>> > > >> > > 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+Revisio...
>> > > >> > > >> > > >> > > >> > > 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
_______________________________________________ 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
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
Thomas, i wouldn't be able to do it alone, i think i should add you as author in the snippet, can i ? 2014-05-21 18:17 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 6:42 PM, walid yaich <[email protected]> wrote:
I finally got it ! Thanks guys :)
This is my listener, it may help someone :
{{velocity}} {{html}} #if ($request.confirm != "1") <form method="get"> <input type="hidden" name="confirm" value="1"/> <input type="submit" class="button" value="Register Event Listener"/> </form> #end {{/html}} {{/velocity}}
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.*
@Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { }
String getName() { return "OnDocumentCreationEventListener" }
List<Event> getEvents() { return Arrays.asList(new DocumentCreatingEvent()) }
void onEvent(Event event, Object source, Object data) { log.info('onEvent begin')
// Current context def crtContext =
Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext')
As I said in the preview mail data is the XWikiContext.
// A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass")
source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully
added
!")
log.info('onEvent end') } }
// Only register the listener if the user has passed confirm=1 in the URL. This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}}
It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added
2014-05-21 15:54 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 4:31 PM, walid yaich <[email protected]> wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference <
http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext <
http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne <[email protected]
:
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...
(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...
> >> > > > >> > > 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+Revisio...
> >> > > > >> > > > >> > > > >> > > > >> > > 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
_______________________________________________ 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
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method: void onEvent(Event event, Object source, Object data) the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Thomas, i wouldn't be able to do it alone, i think i should add you as author in the snippet, can i ?
It's OK, as long as you understood what you did in the end you are the author :)
2014-05-21 18:17 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 6:42 PM, walid yaich <[email protected]> wrote:
I finally got it ! Thanks guys :)
This is my listener, it may help someone :
{{velocity}} {{html}} #if ($request.confirm != "1") <form method="get"> <input type="hidden" name="confirm" value="1"/> <input type="submit" class="button" value="Register Event Listener"/> </form> #end {{/html}} {{/velocity}}
{{groovy}} import org.xwiki.observation.* import org.xwiki.observation.event.* import com.xpn.xwiki.web.* import org.xwiki.bridge.event.DocumentCreatingEvent import org.xwiki.model.reference.LocalDocumentReference import org.xwiki.context.* import groovy.util.logging.*
@Log class OnDocumentCreationEventListener implements EventListener { OnDocumentCreationEventListener() { }
String getName() { return "OnDocumentCreationEventListener" }
List<Event> getEvents() { return Arrays.asList(new DocumentCreatingEvent()) }
void onEvent(Event event, Object source, Object data) { log.info('onEvent begin')
// Current context def crtContext =
Utils.getComponent(Execution.class).getContext().getProperty('xwikicontext')
As I said in the preview mail data is the XWikiContext.
// A Document Reference pointing to the space.page document in an undefined wiki (i.e. without the wiki part) LocalDocumentReference reference = new LocalDocumentReference("RevisionSpace", "RevisionClass")
source.createXObject(reference, crtContext) source.setComment("An XObject of RevisionClass was succesfully added !")
log.info('onEvent end') } }
// Only register the listener if the user has passed confirm=1 in the URL. This is to prevent // from unintentially re-registering the listener against the observation manager. if (request.confirm == "1") { // Register against the Observation Manager def observation = Utils.getComponent(ObservationManager.class) observation.removeListener("OnDocumentCreationEventListener") def listener = new OnDocumentCreationEventListener() observation.addListener(listener) println "{{info}}Listener is now registered {{/info}}" } {{/groovy}}
It's just doesn't log to my console ("log.info" doesn't work) but probably it'll work for others ... but if you try to create any new document you'll find your object added
2014-05-21 15:54 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 4:31 PM, walid yaich <[email protected]> wrote:
I'm sorry, i'm new to xwiki API but i'm really trying to get better ;)
I looked at the API and i find out that i should use this method:
public int *createXObject*(EntityReference <
http://extensions.xwiki.org/?id=org.xwiki.platform:xwiki-platform-model:::/x...
classReference, XWikiContext <
http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org...
context)
But i can't figure out how can i create an EntityReference object and
Usually for a class the easiest is something like:
def reference = new org.xwiki.model.reference.LocalDocumentReference("xclassspace", "xclasspage")
See http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module for more about entity references.
How can i get the context from the actual event caller ?
The event send it as second parameter (like most events actually).
2014-05-21 13:09 GMT+01:00 Thomas Mortagne <[email protected]>:
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...
(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...
>> >> > > >> >> > > 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+Revisio...
>> >> > > >> >> > > >> >> > > >> >> > > >> >> > > 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
_______________________________________________ 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
-- Thomas Mortagne
On 05/21/2014 01:44 PM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method:
void onEvent(Event event, Object source, Object data)
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Note that the xcontext is sent as the "data" parameter as a convenience, since historically there was no other way of getting hold of it. It is not guaranteed that this will continue to happen. The preferred method is still to access the execution context. -- Sergiu Dumitriu http://purl.org/net/sergiu
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it. Sorry... yes, i got it now, but if source is an XWIKIDocument and data is an XWIKIContext, why they are called source and data ? i'll change them in my code to document and context.
The preferred method is still to access the execution context. So i will keep it like that
2014-05-21 18:47 GMT+01:00 Sergiu Dumitriu <[email protected]>:
On 05/21/2014 01:44 PM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method:
void onEvent(Event event, Object source, Object data)
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Note that the xcontext is sent as the "data" parameter as a convenience, since historically there was no other way of getting hold of it. It is not guaranteed that this will continue to happen. The preferred method is still to access the execution context.
-- Sergiu Dumitriu http://purl.org/net/sergiu _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On 05/21/2014 02:11 PM, walid yaich wrote:
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it. Sorry... yes, i got it now, but if source is an XWIKIDocument and data is an XWIKIContext, why they are called source and data ? i'll change them in my code to document and context.
Because the observation module is not only about document changes, but any type of events, in which case the "source" of the event isn't always a document, and the additional data doesn't have to be the context. -- Sergiu Dumitriu http://purl.org/net/sergiu
Clear ! Thanks for the explanation :) 2014-05-21 19:27 GMT+01:00 Sergiu Dumitriu <[email protected]>:
On 05/21/2014 02:11 PM, walid yaich wrote:
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it. Sorry... yes, i got it now, but if source is an XWIKIDocument and data is an XWIKIContext, why they are called source and data ? i'll change them in my code to document and context.
Because the observation module is not only about document changes, but any type of events, in which case the "source" of the event isn't always a document, and the additional data doesn't have to be the context.
-- Sergiu Dumitriu http://purl.org/net/sergiu _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Wed, May 21, 2014 at 7:47 PM, Sergiu Dumitriu <[email protected]> wrote:
On 05/21/2014 01:44 PM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method:
void onEvent(Event event, Object source, Object data)
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Note that the xcontext is sent as the "data" parameter as a convenience, since historically there was no other way of getting hold of it. It is not guaranteed that this will continue to happen. The preferred method is still to access the execution context.
I don't agree, changing parameters coming with an event is a breakage. There will be new events with the new model and those may not pass the XWikiContext but that's all.
-- Sergiu Dumitriu http://purl.org/net/sergiu _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
I don't agree, changing parameters coming with an event is a breakage. There will be new events with the new model and those may not pass the XWikiContext but that's all.
Yep, i didn't change it, not even in my code, thanks :) 2014-05-22 6:32 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 7:47 PM, Sergiu Dumitriu <[email protected]> wrote:
On 05/21/2014 01:44 PM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method:
void onEvent(Event event, Object source, Object data)
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Note that the xcontext is sent as the "data" parameter as a convenience, since historically there was no other way of getting hold of it. It is not guaranteed that this will continue to happen. The preferred method is still to access the execution context.
I don't agree, changing parameters coming with an event is a breakage. There will be new events with the new model and those may not pass the XWikiContext but that's all.
-- Sergiu Dumitriu http://purl.org/net/sergiu _______________________________________________ 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
On Thu, May 22, 2014 at 10:22 AM, walid yaich <[email protected]> wrote:
I don't agree, changing parameters coming with an event is a breakage. There will be new events with the new model and those may not pass the XWikiContext but that's all.
Yep, i didn't change it, not even in my code, thanks :)
I was answering to Sergiu. I'm talking about an event a new version of XWiki changing the parameters send with an event. So not there is absolutely no reason that data is not XWikiContext anytime.
2014-05-22 6:32 GMT+01:00 Thomas Mortagne <[email protected]>:
On Wed, May 21, 2014 at 7:47 PM, Sergiu Dumitriu <[email protected]> wrote:
On 05/21/2014 01:44 PM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
> As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method:
void onEvent(Event event, Object source, Object data)
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Note that the xcontext is sent as the "data" parameter as a convenience, since historically there was no other way of getting hold of it. It is not guaranteed that this will continue to happen. The preferred method is still to access the execution context.
I don't agree, changing parameters coming with an event is a breakage. There will be new events with the new model and those may not pass the XWikiContext but that's all.
-- Sergiu Dumitriu http://purl.org/net/sergiu _______________________________________________ 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
On 05/22/2014 01:32 AM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:47 PM, Sergiu Dumitriu <[email protected]> wrote:
On 05/21/2014 01:44 PM, Thomas Mortagne wrote:
On Wed, May 21, 2014 at 7:25 PM, walid yaich <[email protected]> wrote:
As I said in the preview mail data is the XWikiContext. I'm sorry, i didn't understand exactly what you mean by "data is the XWikiContext."
You are in the following method:
void onEvent(Event event, Object source, Object data)
the second parameter is called data in your code and it's already a XWikiContext object you don't have to do a hack to get it.
Note that the xcontext is sent as the "data" parameter as a convenience, since historically there was no other way of getting hold of it. It is not guaranteed that this will continue to happen. The preferred method is still to access the execution context.
I don't agree, changing parameters coming with an event is a breakage. There will be new events with the new model and those may not pass the XWikiContext but that's all.
Agreed, as long as the event is the same, the parameters will be the same, but we will deprecate org.xwiki.bridge.event.* at some point, once the bridge is no longer relevant. So, in order to make the transition to the future events smoother, it is better to use the future-proof way of accessing the context. Actually, when the bridge won't be needed, XWikiContext will be useless as well. -- Sergiu Dumitriu http://purl.org/net/sergiu
participants (6)
-
Jeremie BOUSQUET -
Sergiu Dumitriu -
Sergiu Dumitriu -
Thomas Mortagne -
vincent@massol.net -
walid yaich