On Mon, Nov 7, 2011 at 2:03 PM, Nigel Smith
<subscriptions(a)nianca.net> wrote:
Hi there
I've got two different groovy classes in two different pages (lets say Widget and
WidgetFactory), and in a third page I'm trying to call an instance of the
WidgetFactory, getting it to create a Widget.
I've included the groovy code for both classes in the third page using the
"wiki.parseGroovyFromPage(…" call, which works as I can successfully call
methods on the widget factory.
However, calling the createWidget method on the factory produces an error, in that the
WidgetFactory code doesn't know anything about Widgets (i.e. it doesn't know about
the Widget class). Am I doing something wrong?
I would like to be able to modularise the code in some way. It doesn't matter if
there are many different classes declared in the one page, or just one; as long as I can
instantiate them, and they know about each other. This would be great as it will mean I
can reuse these classes around a few different pages.
I've tried including the code using the include macro (outside the groovy block) ,
and using the xwiki.includeForm call (inside the groovy block), with no success.
What did you do exactly and what do you mean by "no success" ?
I created the following two pages:
page1:
>>>>>>>>>>>>>>>>>>>>>
{{groovy}}
class MyClass
{
String getString()
{
return "toto".
}
}
{{/groovy}}
<<<<<<<<<<<<<<<<<<<<<<
page2:
>>>>>>>>>>>>>>>>>>>>>
{{include document="page1"/}}
{{groovy}}
myobject = new MyClass()
println myobject.getString()
{{/groovy}}
<<<<<<<<<<<<<<<<<<<<<<
and it's working well for me.
Thanks Thomas -thats working well. I did try this technique, but must have made a mistake
in the original attempt somewhere.
Thanks,
Nigel
Thanks,
Nigel
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs
--
Thomas Mortagne
_______________________________________________
devs mailing list
devs(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/devs