On Wed, Nov 25, 2015 at 10:54 AM, gervwyk <[email protected]> wrote:

> Hello.
> How would I create a new space under Main or the toplevel entity from a
> java
> component. So far I'm doing this, but not sure..
>
> DocumentReference docref = new
> DocumentReference(serverName,pageSpace,pageName);
> if(xwiki.exists( docref, xcontext)){
> //skip create do other stuff
> }else{
>    XWikiDocument doc = new XWikiDocument(docref);
>    doc.setTitle(pageName);
>    DocumentReference docrefparent = new
> DocumentReference(serverName,pageSpace,"WebHome");
>    doc.setParentReference(docrefparent);
>    xwiki.saveDocument(doc, xcontext);
> }
> Where:
>


> serverName = $request.serverName
>

The first parameter is the wiki name, not the server name. If I print
$request.serverName in Velocity I get "localhost" which is not the wiki
name ("xwiki" for the main wiki in my case). $xcontext.database should give
you the name of the current wiki.

Hope this helps,
Marius


> pageSpace = "Main"
> pageName = "NewPage"
>
> is there anything else I need to set on the document or am I referencing
> wrong? Not sure why it is not creating the page..
>
>
>
> --
> View this message in context:
> http://xwiki.475771.n2.nabble.com/Create-spaces-and-page-in-toplevel-space-via-Java-component-tp7596969.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to