On Friday, January 27, 2012 5:27:10 PM UTC+1, Sebastian Gurin wrote:
Ok I found more or less how to do what I want, the following registers a click handler in a native DOM object:public class DomEventTest1 {
public static interface ClickHandler {
void notifyClick(Element source);
}/** call this directly from your Entry point class */
public static void test(RootPanel rootPanel) {
//create a button using gwt DOM
ButtonElement button1 = Document.get().createPushButtonElement();
button1.setInnerHTML("clickme");
Document.get().getBody().appendChild(button1) ;
addClickHandler(button1, new ClickHandler() {
@Override
public void notifyClick(Element source) {
System.out.println("CLICKED");
}
});
}
public static native void addClickHandler(Element e, ClickHandler handler)/*-{
//dirty click handler registration, only for testing
e.onclick=function() {
handler.@org.sgx.gwtraphaljstest.client.js. test.DomEventTest1. ClickHandler::notifyClick( Lcom/google/gwt/dom/client/ Element;)(this);
}
}-*/;
}
Now two quiestion about jsni.The first question is: the statement
handler.@org.sgx.gwtraphaljstest.client.js. test.DomEventTest1. ClickHandler::notifyClick( Lcom/google/gwt/dom/client/ Element;)(this);
is a valid javascript statement? or is it some internal gwt compiler language that is translated to javascript?
What I would like is to be able of represent any javascript function using java objects, like Runnable or other. The main problem for this is be able to call a java instance method from javascript having the java class name, method name and signature in strings. I would like something like:
public static native void callJavaInstMethod(Object javaThisEl, String className, String methodName, String methodSignature, Object[]params)/*-{
//and here do something like:
javaThisEl.@${className}::${methodName}(${ methodSignature})(${params})
}-*/;I tried to archieve something like this unssuccessfully with eval and other hacks. A method like this, will allow me to represent any javascript function using java objects. For example, instead of writing methods like addClickHandler by hand, I could use an Artificial AbstractRunnable class for represent javascript functions as java objects and do:
button1.addClickHandler(new AbstractRunnable1<Element>(){
public void run(Element e) {
System.out.println("CLICKED");
}
});Any ideas on how to call a java instance method from native javascript having all the necesary information in Strings ?
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/INg0raG3T48J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment