Skip to content

Commit

Permalink
Merge pull request #4259 from kwvanderlinde/bugfix/4048-dialog-close-…
Browse files Browse the repository at this point in the history
…not-working-npe

Work around the JavaFX NPE bug causing HTML5 listeners to not be called
  • Loading branch information
cwisniew authored Aug 24, 2023
2 parents b1cf2a0 + 1767e62 commit 70188e3
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.*;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.html.*;

Expand Down Expand Up @@ -79,11 +78,6 @@ public class HTMLWebViewManager {
/** The bridge from Javascript to Java. */
private final JavaBridge bridge;

// Event listener for the href macro link clicks.
private final EventListener listenerA = this::fixHref;
// Event listener for form submission.
private final EventListener listenerSubmit = this::getDataAndSubmit;

/** Represents a bridge from Javascript to Java. */
public class JavaBridge {

Expand Down Expand Up @@ -152,11 +146,11 @@ public void handleAddedNode(Object object) {
if (addedNode instanceof EventTarget) {
EventTarget target = (EventTarget) addedNode;
if (addedNode instanceof HTMLAnchorElement || addedNode instanceof HTMLAreaElement) {
target.addEventListener("click", listenerA, true);
target.addEventListener("click", HTMLWebViewManager.this::fixHref, true);
} else if (target instanceof HTMLFormElement) {
target.addEventListener("submit", listenerSubmit, true);
target.addEventListener("submit", HTMLWebViewManager.this::getDataAndSubmit, true);
} else if (target instanceof HTMLInputElement || target instanceof HTMLButtonElement) {
target.addEventListener("click", listenerSubmit, true);
target.addEventListener("click", HTMLWebViewManager.this::getDataAndSubmit, true);
}
}

Expand All @@ -167,34 +161,34 @@ public void handleAddedNode(Object object) {
nodeList = addedNode.getElementsByTagName("a");
for (int i = 0; i < nodeList.getLength(); i++) {
EventTarget node = (EventTarget) nodeList.item(i);
node.addEventListener("click", listenerA, true);
node.addEventListener("click", HTMLWebViewManager.this::fixHref, true);
}

// Add event handlers for hyperlinks for maps.
nodeList = addedNode.getElementsByTagName("area");
for (int i = 0; i < nodeList.getLength(); i++) {
EventTarget node = (EventTarget) nodeList.item(i);
node.addEventListener("click", listenerA, true);
node.addEventListener("click", HTMLWebViewManager.this::fixHref, true);
}

// Set the "submit" handler to get the data on submission not based on buttons
nodeList = addedNode.getElementsByTagName("form");
for (int i = 0; i < nodeList.getLength(); i++) {
EventTarget target = (EventTarget) nodeList.item(i);
target.addEventListener("submit", listenerSubmit, true);
target.addEventListener("submit", HTMLWebViewManager.this::getDataAndSubmit, true);
}

// Set the "submit" handler to get the data on submission based on input
nodeList = addedNode.getElementsByTagName("input");
for (int i = 0; i < nodeList.getLength(); i++) {
EventTarget target = (EventTarget) nodeList.item(i);
target.addEventListener("click", listenerSubmit, true);
target.addEventListener("click", HTMLWebViewManager.this::getDataAndSubmit, true);
}
// Set the "submit" handler to get the data on submission based on button
nodeList = addedNode.getElementsByTagName("button");
for (int i = 0; i < nodeList.getLength(); i++) {
EventTarget target = (EventTarget) nodeList.item(i);
target.addEventListener("click", listenerSubmit, true);
target.addEventListener("click", HTMLWebViewManager.this::getDataAndSubmit, true);
}
}
}
Expand Down

0 comments on commit 70188e3

Please sign in to comment.