Hi, good to see this group is alive :)
Can I ask another 2 questions?
1. How would I bind an event? In my case I want to handle a button click but the API is unclear to me. (this bytecode to JS thing is still a mystery to me ;))
I have the following code, but it gives me an error when clicked:
HTMLButtonElement button = HTMLButtonElement.$as(document.createElement("BUTTON"));
button.textContent.set("click me");
button.onclick.set((event) -> {
System.out.println("clicked " + event.toString());
return null;
});
My guess is I have to a $as for the lambda as well. But how?
2. I know that only a subset of the Java API is available, which is understandable from a technical and practical viewpoint. But is this easily extendible? For instance java.util.function.Consumer is not available to the runtime. What would it take to implement this on bck2brwsr?
Hope that you can shine a light on my questions.
Thanks
Mauro
Op dinsdag 20 augustus 2019 13:05:12 UTC+2 schreef Jaroslav Tulach:
Amazing solution! Thanks for giving bck2brwsr a try!
-jt
Answering my own question again :)
This does the job:
Document document = Document.$as(getDocument());
Op dinsdag 20 augustus 2019 07:37:43 UTC+2 schreef
mauro...@gmail.com:
Ok, answering part of my own question here. The Dukescript libraries provided exactly this:
These can be obtained by including this dependency:
<dependency>
<groupId>com.dukescript.libraries</groupId>
<artifactId>net.java.html.lib.dom</artifactId>
<version>0.5</version>
</dependency>
But now I'm facing the next hurdle: how to get access to the document. This doesn't work for me:
public static void main(String... args) {
Document document = getDocument();
System.out.println(document.URL());
}
@JavaScriptBody(args = {}, body = "return window.document;")
private static native Document getDocument();
While the getDocument() method actually returned an object, I'm getting errors like these:
TypeError: target.URL__Ljava_lang_String_2 is not a function
Any suggestions?
Op maandag 19 augustus 2019 13:00:20 UTC+2 schreef
mauro...@gmail.com:
Hi,
Is it possible to perform operations on the DOM from Java code?
I'm aware that communicating whit JavaScript can be done using the @JavaScriptBody annotation, but I don't see how to return a HTML element. For primitive types this is working, obviously.
Are there any classes that represent elements from the DOM?
Thanks
--
You received this message because you are subscribed to the Google Groups "bck2brwsr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bck2...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/bck2brwsr/2c4bb440-bb9f-45e5-98b3-f8a3be686fff%40googlegroups.com.