Also, by way of comparison, the "multiple invocation" bug doesn't happen
using the "1.0 way" in a "2.0" document, without wiki-macro-bridge,
using $xwiki.parseGroovyFromPage().
Is there a 2.0 equivalent for $xwiki.parseGroovyFromPage() method suggested
by
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyClassHelloWorldTutorial?
http://jira.xwiki.org/jira/browse/XAWMB-2?focusedCommentId=43681&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_43681
FYI, here, I demonstrate a "regular non macro bridge" way of invoking groovy
in a 2.0 document. It doesn't have the same issues with only outputting the
first instance results:

== Testing parseGroovyFromPage("TestClass1") With 2.0 Syntax ==

Note that [[TestClass1?viewer=code]] is in 1.0 Syntax, per
[[http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyClassHelloWorldTutorial]].
Is there a 2.0 syntax for $xwiki.parseGroovyFromPage()?
==== Initialize $groovyObject ====
{{velocity}}
#set($groovyObject = $xwiki.parseGroovyFromPage("TestClass1"))
$groovyObject.setObjects($xwiki, $context)
{{/velocity}}
==== First Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}
==== Second Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}
==== Third Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}
==== Fourth Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}
==== Fifth Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}
==== Sixth Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}
==== Seventh Call $groovyObject.helloWorld() ====
{{velocity}}$groovyObject.helloWorld(){{/velocity}}

Produces

Testing parseGroovyFromPage("TestClass1") With 2.0 Syntax
Note that TestClass1 is in 1.0 Syntax, per
http://platform.xwiki.org/xwiki/bin/view/DevGuide/GroovyClassHelloWorldTutorial.
Is there a 2.0 syntax for $xwiki.parseGroovyFromPage()?Initialize
$groovyObject
First Call $groovyObject.helloWorld()
Hello World:0
Second Call $groovyObject.helloWorld()
Hello World:1
Third Call $groovyObject.helloWorld()
Hello World:2
Fourth Call $groovyObject.helloWorld()
Hello World:3
Fifth Call $groovyObject.helloWorld()
Hello World:4
Sixth Call $groovyObject.helloWorld()
Hello World:5
Seventh Call $groovyObject.helloWorld()
Hello World:6

With the class defined in a 1.0 document:

/* Groovy Class Called by [Groovy.VelocityCallingTestClass1] #* */

class groovyClass {

def xwiki;
def context;
def call_count = 0;

  void setObjects(xwiki, context) {
    setXWiki(xwiki);
    setContext(context);
  }

  void setXWiki(xwiki) {
    this.xwiki = xwiki;
  }

  void setContext(context) {
    this.context = context;
  }

  String helloWorld() {
    return "Hello World:" + call_count++;
  }
}

/* *# */



Niels
http://nielsmayer.com
_______________________________________________
devs mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/devs

Reply via email to