Dear gervwyk,
From what I understand of components and Javascript, it
will not be
possible. Components are Java code and therefore are executed on
server-side. Velocity, is also script that is executed server-side.
And Javascript is client-side, so it doesn't have the logic for
components. As far as I know, we don't have any possibility to execute
server-side Javascript in XWiki at the moment. So a component doesn't
have much sense for Javascript.
However, instead of following [1], you may also create a REST component
on server-side (which will also allow AJAX). Look [2] for documentation
about writing new REST components. You'll loose a bit of flexibility
(because you'll have to build JAR and restart the wiki each time you
change source code) but you won't have to deal with Velocity.
Note there is also a new extension that may fill your need but I'm not
sure it's exactly what you need [3].
Hope it helps.
[1]
http://extensions.xwiki.org/xwiki/bin/view/Extension/AJAX+example
[2]
http://platform.xwiki.org/xwiki/bin/view/Features/XWikiRESTfulAPI#HCustomre…
[2]
http://extensions.xwiki.org/xwiki/bin/view/Extension/Structured+data+access…
On 28/01/2016 10:30, gervwyk wrote:
Is it possible to call a java component from a
JavaScriptExtension? like
this:
In javascript:
require(['jquery'], function ($) {
$('#ToJava').click(function(){
var returnValue = $services.mycomponent.mymethod( someNumber );
// use return value
});
});
In java:
public int mymethod(int num){
return num +1;
}
I know that I can do the ajax round trip and invoke the method through
velocity:
http://extensions.xwiki.org/xwiki/bin/view/Extension/AJAX+example
-- just wondering if there is a way to shortcut this process by avoiding
velocity and only working in js?
or is my logic flawed?
--
View this message in context:
http://xwiki.475771.n2.nabble.com/calling-a-java-component-from-JavaScriptE…
Sent from the XWiki- Users mailing list archive at
Nabble.com.
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Jean Simard
jean.simard(a)xwiki.com
Research engineer at XWiki SAS
http://www.xwiki.com
Committer on the
XWiki.org project
http://www.xwiki.org