[xwiki-devs] Create Object by Default with a new Page
Hi, i didnt find a documentation for creating an XObject to a Wiki-Page when a new Page is created. I think it must something like that, but who do i place it? EntityReference entRef = doc.resolveClassReference("Space.WhateverClass"); int objectIndex = doc.createXObject(entRef, getXWikiContext()); BaseObject o = doc.getXObjects(entRef).get(objectIndex); I know i can create a new object and page by velocity (http://extensions.xwiki.org/xwiki/bin/view/Extension/Create+Page+With+Object), but i want to add a default and predefined object when a user add a new page. Is there a way to do this from plugin-side? Regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Create-Object-by-Default-with-a-new-Page-t... Sent from the XWiki- Dev mailing list archive at Nabble.com.
Hi Matthias, The recommended approach is to use a page template. See the FAQ tutorial for instance http://platform.xwiki.org/xwiki/bin/view/DevGuide/FAQTutorialManual . You create a page that will serve as a template. You add an object of the desired type to this page and fill the object properties with the default values. Then you use this page as a template when creating new pages. See also the template provider feature http://extensions.xwiki.org/xwiki/bin/view/Extension/Administration+Applicat... . If you want to add the object even when the user creates a plain wiki page then you need to write an event listener that catches the document creation event and adds the object. It can be written in Groovy, Java (check extensions.xwiki.org for examples) or as a Wiki component I think ( http://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent+Module ). Hope this helps, Marius On Fri, Oct 18, 2013 at 10:25 PM, Matthias Wegner <[email protected]> wrote:
Hi,
i didnt find a documentation for creating an XObject to a Wiki-Page when a new Page is created.
I think it must something like that, but who do i place it? EntityReference entRef = doc.resolveClassReference("Space.WhateverClass"); int objectIndex = doc.createXObject(entRef, getXWikiContext()); BaseObject o = doc.getXObjects(entRef).get(objectIndex);
I know i can create a new object and page by velocity (http://extensions.xwiki.org/xwiki/bin/view/Extension/Create+Page+With+Object), but i want to add a default and predefined object when a user add a new page.
Is there a way to do this from plugin-side?
Regards, Matthias
-- View this message in context: http://xwiki.475771.n2.nabble.com/Create-Object-by-Default-with-a-new-Page-t... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Hi Marius, i tried to use the EventListener and DocumentUpdateEvent (described in http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial). But i dont want to put the listener in the plugin, so i need to compile it. This not work because the class is not in my classpath. At the moment i am using the standalone xwiki-version 5.1 with jetty and hsqldb. I tried to find the right maven-dedencency for DocumentUpdateEvent. Do you know which pom i need? In xwiki-commons-observation-api the DocumentUpdateEvent is not contained. Regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Create-Object-by-Default-with-a-new-Page-t... Sent from the XWiki- Dev mailing list archive at Nabble.com.
DocumentUpdatedEvent is in xwiki-platform-bridge Hope this help Marius On Oct 26, 2013 10:39 AM, "Matthias Wegner" <[email protected]> wrote:
Hi Marius,
i tried to use the EventListener and DocumentUpdateEvent (described in
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyNotificationTutorial ). But i dont want to put the listener in the plugin, so i need to compile it. This not work because the class is not in my classpath. At the moment i am using the standalone xwiki-version 5.1 with jetty and hsqldb. I tried to find the right maven-dedencency for DocumentUpdateEvent. Do you know which pom i need? In xwiki-commons-observation-api the DocumentUpdateEvent is not contained.
Regards, Matthias
-- View this message in context: http://xwiki.475771.n2.nabble.com/Create-Object-by-Default-with-a-new-Page-t... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
I did't found it in the sources before, because the class is "DocumentUpdatedEvent" and not "DocumentUpdateEvent" (as described in the tutorial). Now it works fine. At the moment i put the new listener to the ObservationManager when one of my components is initialized (Components imlements Initializable). I use here @Inject ObservationManager observationManager; @Override public void initialize() throws InitializationException { observationManager.addListener(new MyOwnEventListener()); } Is there a way to add the new listener in general to the ObersvationManager when Xwiki starts? Regards, Matthias -- View this message in context: http://xwiki.475771.n2.nabble.com/Create-Object-by-Default-with-a-new-Page-t... Sent from the XWiki- Dev mailing list archive at Nabble.com.
As far as I know you don't have to manually add the event listener. It's enough to implement the EventListener interface as a component (using the proper annotations like @Component and @Named). The observation manager looks up all event listener components using the component manager. Hope this helps, Marius On Oct 26, 2013 10:06 PM, "Matthias Wegner" <[email protected]> wrote:
I did't found it in the sources before, because the class is "DocumentUpdatedEvent" and not "DocumentUpdateEvent" (as described in the tutorial). Now it works fine. At the moment i put the new listener to the ObservationManager when one of my components is initialized (Components imlements Initializable). I use here
@Inject ObservationManager observationManager;
@Override public void initialize() throws InitializationException { observationManager.addListener(new MyOwnEventListener()); }
Is there a way to add the new listener in general to the ObersvationManager when Xwiki starts?
Regards, Matthias
-- View this message in context: http://xwiki.475771.n2.nabble.com/Create-Object-by-Default-with-a-new-Page-t... Sent from the XWiki- Dev mailing list archive at Nabble.com. _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (2)
-
Marius Dumitru Florea -
Matthias Wegner