<
From version < 40.1 >
edited by Sergiu Dumitriu
on 2012/05/19
To version < 41.1 >
edited by Vincent Massol
on 2012/05/19
>
Change comment: Document new SS for Components

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.Sergiu
1 +XWiki.VincentMassol
Content
... ... @@ -71,22 +71,40 @@
71 71  * [[The Request object>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/web/XWikiRequest.html]]: **##request##**
72 72  * [[The Response object>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/web/XWikiResponse.html]]: **##response##**
73 73  * [[The XWiki object>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/api/XWiki.html]]: **##xwiki##**
74 -* [[The XWiki utils>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/api/Util.html]]: **##util##**
74 +* [[The XWiki utils>>http://maven.xwiki.org/site/xwiki-core-parent/xwiki-core/apidocs/com/xpn/xwiki/api/Util.html]]: **##util##** (this is deprecated)
75 +* Various [[Script Services>>extensions:Extension.Script Module]]: **##services##**
75 75  
76 76  == [[XWiki Component>>extensions:Extension.Component Module]] Access ==
77 77  
78 -You can also gain direct access to XWiki components using the following code snippet (also see: [[Accessing components from Groovy>>DevGuide.WritingComponents#HAccessingacomponentfromgroovy]]):
79 +Since XWiki 4.1M2+ there's a Script Service to access the Component Manager (see also: [[Accessing components from Groovy>>DevGuide.WritingComponents#HAccessingacomponentfromgroovy]]).
79 79  
81 +For example using Groovy you'd write:
82 +
83 +{{code language="java"}}
84 +{{groovy}}
85 +def greeter = services.component.getInstance(org.xwiki.component.HelloWorld.class)
86 +println greeter.sayHello()
87 +{{/groovy}}
88 +{{/code}}
89 +
90 +You can also get the ComponentManager with:
91 +
92 +{{code language="java"}}
93 +{{groovy}}
94 +def cm = services.component.componentManager
95 +{{/groovy}}
96 +{{/code}}
97 +
80 80  {{info}}
81 -This snippet is written in Groovy and will have to be converted to your scripting language.
82 -{{/info}}
99 +With versions of XWiki older than 4.1M2 you'd use (in Groovy):
83 83  
84 84  {{code language="java"}}
85 85  {{groovy}}
86 -def greeter = com.xpn.xwiki.web.Utils.getComponent(org.xwiki.component.HelloWorld.class);
87 -println greeter.sayHello();
103 +def greeter = com.xpn.xwiki.web.Utils.getComponent(org.xwiki.component.HelloWorld.class)
104 +println greeter.sayHello()
88 88  {{/groovy}}
89 89  {{/code}}
107 +{{/info}}
90 90  
91 91  == XWiki Core Access ==
92 92  

Get Connected