Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-4542

MissingPropertyException: Groovy script works with XWiki Syntax 2.0 but not with XWiki Syntax 1.0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Fix
    • Major
    • None
    • 1.9.4
    • Groovy, Scripting
    • None
    • XWiki 1.9.4, MySQL 5.1.40, Tomcat 6.0.20, Java 1.6.0, Debian GNU/Linux 5.0
    • Unknown

    Description

      1. Create the following document tree. Use XWiki Syntax 2.0.

      • Parent
        • ChildPage1
          • ChildPage2
          • ChildPage3
            • ChildPage4
          • ChildPage5
            • ChildPage6
            • ChildPage7
        • ChildPage8

      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.

      Attachments

        Activity

          People

            sdumitriu Sergiu Dumitriu
            c Clemens Fuchslocher
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: