• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Warn user when have unsaved data

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
M. LaBarre
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic