wood burning stoves 2.0*
The moose likes JSF and the fly likes Warn user when have unsaved data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Warn user when have unsaved data" Watch "Warn user when have unsaved data" New topic
Author

Warn user when have unsaved data

M. LaBarre
Greenhorn

Joined: Jan 10, 2008
Posts: 2
Everything I have read about about how to accomplish this uses the onBeforeUnload event. But this event is called when a page refreshes as well as when the page is unloading.

I can easily use my backing bean to determine when the user needs to save but what I can't figure out is how to tell the difference before a page refresh vs a page unload.

Is there some way I can determine the current page == target page from the Faces Context?

I envision something like this

window.onbeforeunload = function() {
var needToSave = ${pc_myform};
if (needToSave == true) {
check if target page != current page)
alert("you need to save")
return false;
}
}
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

OK, so why would the page/form refresh while still being "dirty"? I can see the user clicking the refresh button, but warn the user then too, because I would assume that the refresh could refresh the page to show the older data values, and therefore lose your unsaved data.

Meaning I am thinking the way it is operating is the way you should want it. But I could be clueless, it wouldn't be the first time.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
M. LaBarre
Greenhorn

Joined: Jan 10, 2008
Posts: 2
Let me try to explain this better.

I have a form where the user can add favorite forms to their profile. The users insist on having a save and cancel button, so I can't persist the data immediately. Each time they add a new favorite, or remove one, the screen is updated to display this change(so the page gets refreshed) but the data is not saved until they click on the save button or the changes are reverted back if they click on the cancel button. But there are other links the user can click on that will navagate away from the page.

This gets a but more complicated in that there is a parent page, that holds several iframes with other pages. And it's the iframe pages where the data can be updated.

So the onBeforeUnload event would be the best option if I could only determine what the current page is and what the target page is.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Warn user when have unsaved data