I need to add a behavior to ModalWindow such that when a user clicks outside of the modal, if a certain condition is met (checked server-side in my respond() method), the modal is dismissed.
I tried implementing something based on this answer. The problem is that I can't attach a click listener to the modal window div because it's not added to the DOM until the modal is shown (the example attaches a keyup to the document itself.)
I thought of extending ModalWindow and adding the JS via getShowJavascript(), but then I don't have any means to connect it to an AbstractDefaultAjaxBehavior.respond() method for the test.