How to call codenameone java class method from javascript? -


i have codenameone class contains method of upload file mobile app.i want call codenameone class method javascript function while user click on upload button.

below codenameone class method going upload file.

public void actionperformed1(){      if (filechooser.isavailable()) {         filechooser.showopendialog("image/*", e2-> {             string file=null;             if(e2!=null){                 file = (string)e2.getsource();             }             if (file == null) {                 hi.revalidate();             } else {                 string extension = null;                 if (file.lastindexof(".") > 0) {                     extension = file.substring(file.lastindexof(".")+1);                 }                 if ("txt".equals(extension)) {                     filesystemstorage fs = filesystemstorage.getinstance();                     try {                         inputstream fis = fs.openinputstream(file);                         hi.addcomponent(new spanlabel(util.readtostring(fis)));                     } catch (exception ex) {                         log.e(ex);                     }                 } else {                     hi.add("selected file "+file);                 }             }             hi.revalidate();         });     } 

below html file using javascript call codenameone actionperformed1() method.

<pre>     type="button" value="call method"         onclick = "document.filechooserdemo.actionperformed1()"  </pre> 

what can in javascript call codenameone method?

thank you.

check out javadocs javascript package section titled "calling java methods javascript".

jsobject logger = (jsobject)ctx.get("{}"); logger.set("log", new jsfunction(){      public void apply(jsobject self, object[] args) {         string msg = (string)args[0];         log.p("[javascript logger] "+msg);     }  });  ctx.set("window.logger", logger); 

then javascript work:

logger.log('this test message'); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -