Details
Description
1. Create the following document tree. Use XWiki Syntax 2.0.
- Parent
- ChildPage1
- ChildPage2
- ChildPage3
- ChildPage4
- ChildPage5
- ChildPage6
- ChildPage7
- ChildPage8
- ChildPage1
2. Add the createDocumentTree Groovy script to the Parent document:
{{groovy}} def createDocumentTree(document, depth = 5, level = 1) { def translated = document?.getTranslatedDocument() def prefixed = translated?.getPrefixedFullName() def title = translated?.getDisplayTitle() def children = xwiki.searchDocuments("where doc.parent = '${translated}' or doc.parent = '${prefixed}'") children.each { child -> if (depth == 0) { return } document = xwiki.getDocument(child) translated = document?.getTranslatedDocument() prefixed = translated?.getPrefixedFullName() title = translated?.getDisplayTitle() println "*" * level + " [[${title}>>${prefixed}]]" createDocumentTree(document, depth - 1, level + 1) } } createDocumentTree(doc) {{/groovy}}
3. The document tree is correctly displayed. There is no error.
4. Remove the script from the document.
5. Convert the document to XWiki Syntax 1.0.
6. Add the following Groovy script to the document:
<% def createDocumentTree(document, depth = 5, level = 1) { def translated = document?.getTranslatedDocument() def prefixed = translated?.getPrefixedFullName() def title = translated?.getDisplayTitle() def children = xwiki.searchDocuments("where doc.parent = '${translated}' or doc.parent = '${prefixed}'") children.each { child -> if (depth == 0) { return } document = xwiki.getDocument(child) translated = document?.getTranslatedDocument() prefixed = translated?.getPrefixedFullName() title = translated?.getDisplayTitle() println "*" * level + " [${title}>${prefixed}]" createDocumentTree(document, depth - 1, level + 1) } } createDocumentTree(doc) %>
7. Now, the following exception is displayed:
groovy.lang.MissingPropertyException: No such property: tdoc for class: Script1
8. Replace the line
println "*" * level + " [${title}>${prefixed}]"
with
println "*" * level + " [" + title + ">" + prefixed + "]"
or
println "*" * level + " [\${title}>${prefixed}]"
9. The error does not occur anymore.
Why does this Groovy script behave differently under XWiki Syntax 2.0 and 1.0?
Maybe a bug.