Changes will be lost
How does one implement a "Changes will be lost. Proceed Yes/No" kind of functionality with JSF? If a user has altered some data on a form and navigates away without saving, I'd like to 'hear' that event and notify them. Ideally, I'd want to trigger the notification code if they navigate to external sites too, but I can live with detecting this condition within my site only. If one waits to do this in a simple action method, there is no easy way to interact with the user, but managing it in javascript seems onerous (at least to me :) Any better ideas? Thanks
Shane
# 1
This is only possible with clientside stuff, like JavaScript, because navigating away is not a HTTP form submit action, so serverside languages as JSF for sure cannot be used. Googling using the keyword "onunload" might give interesting results =)
If you really want to do this with JSF: make all navigation links UICommand form actions using h:commandLink or h:commandButton instead of h:outputLink or even a href links. Implement valueChangeListeners in every UIInput component and compare getNewValue() with getOldValue() to see if something is changed. But this all will not work if you use the browser back button or close button.