简体   繁体   English

在页面退出时检测到PrimeFaces中的UI组件的客户端更改?

[英]Detecting client-side changes to UI components in PrimeFaces on page exit?

I'd like to implement warning message when leaving the page, that the unsaved changes will be lost. 我想在离开页面时实施警告消息,未保存的更改将丢失。 However, to do that correctly, I need to know if the PrimeFaces components were changed on the client side. 但是,要正确执行此操作,我需要知道客户端上的PrimeFaces组件是否已更改。

Is there an existing mechanism that I can use? 我可以使用现有的机制吗? I've thought about registering keydown listener on all inputs and textareas, but the content of that fields can be changed also by mouse events. 我曾考虑过在所有输入和文本区域上注册keydown侦听器,但是该字段的内容也可以通过鼠标事件来更改。 On the other hand, onblur won't be fired if the focus is inside field and then the page is closed, so such change won't be detected. 另一方面,如果焦点位于字段内然后关闭页面,则不会触发onb​​lur,因此不会检测到此类更改。 I've tested also, that registering onchange on some components (like selectOneMenu, autoComplete) is not working when the change is made with mouse. 我也测试过,用鼠标进行更改时,在某些组件(如selectOneMenu,autoComplete)上注册onchange无效。

There is no complete existing mechanism. 没有完整的现有机制。

But you can either a ValueChangeListener that gets called on value change or use a javascript function with the onChange attribute inside your element. 但是,您可以在值更改时调用ValueChangeListener ,也可以在元素内使用具有onChange属性的javascript函数。

I've tested also, that registering onchange on some components (like selectOneMenu, autoComplete) is not working when the change is made with mouse. 我也测试过,用鼠标进行更改时,在某些组件(如selectOneMenu,autoComplete)上注册onchange无效。

This depends on the browser you are using. 这取决于您使用的浏览器。 To make sure everything is working I would test onClick and check if the value inside the element has actually changed. 为了确保一切正常,我将测试onClick并检查元素内的值是否确实发生了变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM