[xwiki-devs] How can I use a method with parameter in component
I want to build a component ,but I didn't get it .I just use the HelloWorld as a example interface like this: @ComponentRole public interface HelloWorld { String sayHello(String name); } and script like this : @Component @Named("hello") @Singleton public class HelloWorldScriptService implements ScriptService { @Inject private HelloWorld helloWorld; public String greet(String name) { return this.helloWorld.sayHello(name); } } aa I use it in xwiki like this : {{velocity}} $services.hello.greet("aaa") {{/velocity}} but I didn't get the right result,I must make some mistakes at some steps I'm not clear,can you help me,please .
You don't have to do anything special to have a method with parameters in a component. Are you saying that it worked without the parameter and it doesn't work after you added the parameter? Did you restart the server after updating the component jar in WEB-INF/lib ? Review the steps from http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents#HTheComp... to make sure you haven't missed something. Hope this helps, Marius On Tue, Mar 13, 2012 at 4:26 AM, jinlong liu <liujinlong5788@gmail.com> wrote:
I want to build a component ,but I didn't get it .I just use the HelloWorld as a example interface like this: @ComponentRole public interface HelloWorld {
String sayHello(String name); } and script like this : @Component @Named("hello") @Singleton public class HelloWorldScriptService implements ScriptService { @Inject private HelloWorld helloWorld;
public String greet(String name) { return this.helloWorld.sayHello(name); } } aa I use it in xwiki like this : {{velocity}} $services.hello.greet("aaa") {{/velocity}} but I didn't get the right result,I must make some mistakes at some steps I'm not clear,can you help me,please . _______________________________________________ devs mailing list devs@xwiki.org http://lists.xwiki.org/mailman/listinfo/devs
participants (2)
-
jinlong liu -
Marius Dumitru Florea