Show dirty area (Custom warning message) dialog in JSF/ Primefaces -


i working on primefaces application,

if changed in page, , clicked page without saving, need show popup dialog saying that, hey changed want save or not, based on user selection should either save/cancel/no function.

i seen link, to track changes in jsf,

if in same bean class , clicked on cancel button, can write function , show dialog.

but, if user clicked on other link/page or menu item how handle case.

is there anyway like, before flow go other bean last method should called.

as searched because of security browsers not showing custom warning messages.

@predestroy public void destroy() { ..} 

i tried this, method not getting called correctly if click on other link every time. there other way?

to capture changes in application, may need introduce dirty flag, if of component value getting changes, application should set dirty flag value true. below example.

<h:inputtext id="someid" onchange="setdirty();"     value="#{mymanager.name}" maxlength="100"> 

user try navigate next page, without saving, windowbeforeunloadlistener trigger first, check boolean variable, if value true, show validation popup.

var dirty = true; window.onunload = windowunloadlistener; window.onbeforeunload = windowbeforeunloadlistener; window.onload = windowloadlistener;  /*  * listener window-onbeforeunload event.  * called before unloading (leaving current page) window.  * function checks dirty flag , pops   * message confirm wit user.   */ function windowbeforeunloadlistener() {    if(dirty) {        return "you have used navigation controls not part of page.\n\n         if wish end, click 'leave page'. "        + "your session end here.\n\n"        + "if wish continue use please click 'stay on page'.";     } } 

on page load , on save, set dirty flag value false.

/*  * listener window-onload event.  * called every time new page loaded.  * function reset flag.    */ function windowloadlistener(){     dirty= true; } 

note: custom validation message won't work in ie. shows default browser validation message.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -