If you need to call a Java action, could you not just add a button to trigger a microflow that will call the Java action and save the data?
https://docs.mendix.com/refguide/button-widgets
I think you are mixing up Java and JavaScript hence we can’t properly help you. If I look at your question it seems you want to trigger some functionality on click of a button. You can trigger JavaScript via a JavaScript action in a nanoflow or Java via a Java action with a microflow.
Could you share your real use case? What are you trying to achieve?
I have some javascript code in a Javascript snippet that I want to execute when the Save button is pressed.
However the Javascript snippet is not trigged by the Save button event.
Javascript code within the snippet:
document.addEventListener("myBtn", function(event) {
this._contextObj.set('Weight', 2);
});