Skip to content Skip to sidebar Skip to footer

Vaadin JavaScript Popup Only Works First Time In Each Session

I have an application which requires a process to be cleaned up regardless of how the user exits the page. I'm using JavaScript to detect when the user exits the page via tab or br

Solution 1:

This might be a long shoot however I had the same problem with Vaadin few months ago. What worked for me was to assign function to the variable and then pass it to the another function. Change your code to this one and have a try:

JavaScript.getCurrent().execute(
    "someGlobal = function beforeCloseListener(e) { var e = e || window.event; var message = " + LEAVE_PAGE_MESSAGE + "; if(e)       e.returnValue = message; return message; } " +
    "window.addEventListener('beforeunload', someGlobal);"
);

Solution 2:

I have now found the answer to my problem. Essentially, I was calling Vaadin's JavaScript.exectute() method from within a ScheduledExecutorService. JavaScript does not like being called asynchronously, so I had the required methods being called within a UI.getCurrent().access() block. I was under the impression that this would cause the javascript code I need to be run synchronously on the UI thread. Apparently this was not the case.

Moving my javascript.execute() calls outside of the executor and into the main thread has solved my problem, as in my case it is acceptable for my JavaScript to be run synchronously. I will be looking more into the UI.access() method to see whether the behaviour I had expected is meant to work and if not, whether there are any better alternatives to get the JavaScript to run in an asynchronous environment. I hope to add this information to my answer if I find anything useful.


Post a Comment for "Vaadin JavaScript Popup Only Works First Time In Each Session"