On Thu, Nov 24, 2016 at 10:16 AM, Pascal BASTIEN
<pbasnews-xwiki(a)yahoo.fr> wrote:
Hello xwiki users
I need a little bit of light about reference.
I use this methods, hasParent(EntityReference expectedParent) and i noticed that I can
not use string to set EntityReference.
Then i must use this before: "#set ($reference =
$services.model.resolveSpace('xwiki:Encyclopédie'))" and
"$doc.documentReference.hasParent($reference)" because
$doc.documentReference.hasParent('xwiki:Encyclopédie') doesn't work.
Am I right? Anyway, I can understand that.
There is one magic thing about Velocity in XWiki that you need to keep
in mind: it automatically convert parameters to the right type (when
there is a converter provided for that type).
For example the converter for the type EntityReference understand the
following syntax: [<entitytype>:]<entityreference> (the default entity
type is "document" if you don't provide it) so the space with
reference "xwiki:Encyclopédie" will be the string
"space:xwiki:Encyclopédie" as in
hasParent('space:xwiki:Encyclopédie').
Another point about documentation
http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptSe…
(because I spend a lot of time to identify my issue because the "x" characters:
Create a Document Reference: "#set ($reference =
$services.model.createDocumentReference("wiki", ["space"],
"page"))"
but
$doc.documentReference.spaceReferences.get(0) display "Space
xwiki:Encyclopédie".
Reference use "xwiki" but createDocumentReference use "wiki"?
"wiki" is it a wiki name example?
I don't really understand your example
$services.model.createDocumentReference("wiki", ["space"],
"page")
have nothing to do with $doc.documentReference. It just means you are
executing this script on main wiki ("xwiki").
Another question:
What is the difference between: $services.model.createDocumentReference and
services.model.resolveDocument?
With resolveDocument the Page must exist?
Can I use CreateDocumentReference if target document exist?
resolveDocument take a reference as a String and parse it (it's using
a DocumentResolver component for this) and find what is not provided
in the String (by default from the context) while
createDocumentReference takes each element of the reference separately
and know nothing about reference syntax.
Last point:
I think these 2 simples examples missing in:
http://extensions.xwiki.org/xwiki/bin/view/Extension/Model+Module#HScriptSe…
#set ($reference = $services.model.resolveSpace('xwiki:MySpace'))
#set ($reference = $services.model.resolveSpace('xwiki:MySpace.MyPage'))
What do you think?
Not sure people create space references that much but sure why not.
Ty
Pascal B
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Thomas Mortagne