Glad you found the answer and thanks for posting the solution. -Vincent On Jan 12, 2009, at 3:37 PM, Ajdin Brandic wrote:
Hi again
My problem was that in my Velocity script (page3) I forgot to add "$" in front of some variable names (Groovy doesn't use "$") so the real values were not passed across correctly and the object was not created correctly therefore NullPointerException (Null Pointer Exception).
Anyway, for those who get stuck like me, this is the correct way to include groovy class within another groovy class.
Velocity script : #set($wsd = $xwiki.parseGroovyFromPage("GroovyScripts.Class1")) #set($discard2 = $wsd.setXWiki($xwiki, $context));
Groovy Class1: def groovyHTTP = xwiki.parseGroovyFromPage("GroovyScripts.Class2"); //then groovyHTTP.someMethod(someParam);
Groovy Class2: //some methods
********************* Some tags: Include groovy class in velocity script, pass value from velocity to groovy *********************
Ajdin
-----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Ajdin Brandic Sent: 12 January 2009 13:50 To: XWiki Users Subject: [xwiki-users] Scripting issue - xwiki
Hi
I wander if anyone can help. I have found a discussion on IRC between users "asyd" and "lucaa" but the was no answer to the problem.
I have two Groovy Classes saved as two pages page1 and page2. I also have some scripting outside class in page1. So page1 class requires an instance of page2 class and I use xwiki.parseGroovyFromPage("somespace.page2") which works fine until I introduce a third page / script called page3.
In page3 I use xwiki.parseGroovyFromPage("somespace.page1") "REMEMBER: page1 also uses parseGroovyFromPage to call page2". I get NullPinterException when page1 class tries to access a method of page2 class. I then tried to create an instance of page1 and page 2 classes in my page3 script then pass page2 instance as parameter to page1 but still the same error.
Is there any way around this except putting all content (page1 and page2) into one class?
I would really appreciate some feedback. If you require the code to be sent I'll gladly do that.
Thanks Ajdin B.
--------------------------------------------------------
NOTICE
This message and any files transmitted with it is intended for the addressee only and may contain information that is confidential or privileged. Unauthorised use is strictly prohibited. If you are not the addressee, you should not read, copy, disclose or otherwise use this message, except for the purpose of delivery to the addressee.
Any views or opinions expressed within this e-mail are those of the author and do not necessarily represent those of Coventry University.
Thanks -Vincent http://xwiki.com http://xwiki.org http://massol.net