Thanks Jean.
Yes, I understand. I think what would be useful, is a JS function to invoke
a java method server-side, since I find myself doing this ajax round trip
all the time. So what I'm proposing a JS function call, say:
JavaServer.call("mycomponent.mymethod", {JSON data input}, "(return
type)'
);
Which runs the ajax in JS required calling a generic xwiki page url with a
velocity script maybe which invokes the java component passed with the JS
parameter and return the "html/text" or "application/json" data as
specified.
Currently I have like 50 static terminal pages which is only used to pass
data from the JS with ajax to a velocity script to a java component and
back. Basically, the only difference in those velocity scripts is the
method name. So kinda feel that it might be possible to "short-cut' this
velocity page, with a standard velocity macro which invokes the passed
method. I'm pretty sure this will add client side "reactive"-like
functionality to xwiki as you can invoke server-side functions from JS
events. In principle like in Meteor.js were you do a
Method.call("methodname",function(){}), although the underlying
architecture differs greatly.
Keep up the good work
Gerrie van wyk
On Thu, Jan 28, 2016 at 11:56 AM, Jean SIMARD [via XWiki] <
ml-node+s475771n7597706h36(a)n2.nabble.com> wrote:
  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
 [hidden email] <http:///user/SendEmail.jtp?type=node&node=7597706&i=0>
 
http://lists.xwiki.org/mailman/listinfo/users
 
 --
 Jean Simard
 [hidden email] <http:///user/SendEmail.jtp?type=node&node=7597706&i=1>
 Research engineer at XWiki SAS
 
http://www.xwiki.com
 Committer on the 
XWiki.org project
 
http://www.xwiki.org
 _______________________________________________
 users mailing list
 [hidden email] <http:///user/SendEmail.jtp?type=node&node=7597706&i=2>
 
http://lists.xwiki.org/mailman/listinfo/users
 ------------------------------
 If you reply to this email, your message will be added to the discussion
 below:
http://xwiki.475771.n2.nabble.com/calling-a-java-component-from-JavaScriptE…
 To unsubscribe from calling a java component from JavaScriptExtension, click
 here
<http://xwiki.475771.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7597705&code=Z2Vydnd5a0BnbWFpbC5jb218NzU5NzcwNXwxMTM4MjQ1OTI0>
 .
 NAML
<http://xwiki.475771.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
 
--
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.