I want to send the the data in my arraylist in java to an array in js. I searched on the web but I am still not sure how to do it. I saw someone tried to do it by writing the js and javacode together. How can I do it separately? In other words, java code and js code are separate. Please the picture below. I want to use javaFx or something that does not need to go through the internet like jsp. Thank you so much.
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
public class SendData extends Application{
Button send;
@Override
public void start(Stage stage) throws Exception {
WebView myWebView = new WebView();
WebEngine engine = myWebView.getEngine();
ArrayList<String> arr = new ArrayList<String>();
arr.add("string1");
arr.add("string2");
arr.add("string3");
arr.add("string4");
arr.add("string5");
send = new Button("send_to_js");
send.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
/*?*/
}
});
VBox vb = new VBox();
vb.getChildren().addAll(myWebView, send);
Scene scene = new Scene(vb, 500, 500);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
$(document).ready(function() {
/* how do I put the data into the array*/
var receiver = [...];
});