-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everybody.
I'm looking for a way to integrate a Java Applet into our ZK application in order to get data from a fingerprint reader for a login window. I've read a 2009 smalltalk but as far as I can tell it's already obsoleted. I'm using a single ZUL file as the application entry point (as index.zul), and everything else is being created programatically via the Java ZK API. Any pointers in the right direction will be greatly appreciated.
Best regards and thanks in advance.
I don't think there have been fundamental changes to the JS <-> Applet communication in the last 10 years, and also I am not aware of changes to the ZK client API, so I tested myself with a very simple example (I assume you already have your applet running so I'll not bore you with applet security related issues).
assume an applet like this
import java.applet.Applet;
import netscape.javascript.*;
public class TestApplet extends Applet {
private JSObject js;
@Override
public void init() {
super.start();
js = JSObject.getWindow(this);
js.eval("console.log('applet init')");
}
public void echoJS(String script) { //called from JS
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
js.eval(script); //calling back into JS
}
}
It has a public method echoJS
that performs in- and outbound communication...
embed the applet in a zk page
<zk>
<applet id="myapplet" code="TestApplet.class"
mayscript="true" onFingerPrint="System.out.println(event.getData());"/>
</zk>
or in your case create the Applet component in Java
org.zkoss.zul.Applet applet = new org.zkoss.zul.Applet();
applet.setId("myapplet");
applet.setMayscript(true);
applet.setCode("TestApplet.class");
applet.setParent(yourParentComponent);
//register a custom event listener
applet.addEventListener("onFingerPrint", new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
System.out.println(event.getData());
}
});
When you want to call the echoJS method on your applet just call from java (ZK webapp):
String script = "jq('@myapplet')[0].echoJS('alert(\"hello something\")')"
Clients.evalJavaScript(script);
To fire the "onFingerPrint" event from inside your Applet code just call:
String script = "zk.Widget.$('$myapplet').fire('onFingerPrint', {data: 'somedata'}, {toServer: true})";
js.eval(script);
please let me know if this was helpful.
Regards,
Robert
Asked: 2014-02-10 23:30:37 +0800
Seen: 25 times
Last updated: Feb 13 '14
are you having trouble embedding the applet into the website, or do you need hints how to communicate from the applet via JS/Ajax to the server?
cor3000 ( 2014-02-11 02:03:08 +0800 )editYes, it's about the applet communication. As I've said in my post, I'm using just an index.zul file as my application entry point, and from there all the user interface is generated via Java classes. My index.zul file uses a Java class that extends from the Window ZK class (no Composer, just Window)
mrojas ( 2014-02-11 15:41:38 +0800 )editCan you provide which API you use for fingerprint
sitansu ( 2014-02-12 16:28:51 +0800 )editHi @sitansu I'm going to use Suprema BioMini readers and their SDK. Regards.
mrojas ( 2014-02-12 18:02:38 +0800 )edit