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

Velocity scripts in component methods should not change $doc

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 13.10.3
    • Component
    • None
    • Unknown

    Description

      Steps to reproduce:

      1. create an event listener in a wiki page as explained in https://extensions.xwiki.org/xwiki/bin/view/Extension/WikiComponent%20Module#HImplementingmethods ; the listner should listen to DocumentUpdatingEvent at least.
      2. instead of a groovy macro use a velocity macro in the method code body, like
        {{velocity}}
         ##
        {{/velocity}}

        (The comment symbols are important, a wholly empty velocity code block does not reproduce the issue

      1. go to and "AppWithinMinutes" generated application, and click on "Edit Application" (I tried this with the pre-installed "Movies" Application: http://localhost:8080/xwiki/wiki/subwiki1/view/Help/Applications/Movies/
      2. in the "Step 2 — Structure your data" do not update anything, just click "Next Step"

      Expected behavior:

      • the next step ("Step 3 — Locate your data") should be shown

      Actually observed:

      • a different page is shown, with the page name of the event handler page, appended by TemplateProvider

      (Instead of implementing the event listener you can also import the attached xar: Sandbox.Surprise.xar )

      The problem seems to occur because the velocity macro is executed in a velocity context shared with the velocity code of the page AppWithinMinutes.ClassEditSheet in the #macro(updateAndSaveClass)

        ##
        ## Save
        ##
        #if(!$errorMessage)
          #set($discard = $xdoc.setXClass($xclass))
          #set($discard = $xdoc.renameProperties($doc.documentReference, $fieldsToRename))
          #set($discard = $xdoc.setHidden(true))
          #set($discard = $xdoc.setMetaDataDirty(true))
          ####  here before the save $doc points to the class under edit
          #set($discard = $doc.save($services.localization.render('core.comment.updateClassProperty'), $minorEdit))
          ####  here after the save $doc points to the event listener page 
       #end
      

      (Comments starting with #### are inserted by me and not part of the platform code.)

      Obvious workaround: do not use velocity macros for event listeners in wiki pages, but use groovy-macros (you need programming rights anyway.)

      Attachments

        Activity

          People

            Unassigned Unassigned
            camil7 Clemens Robbenhaar
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: