/login.xhtml
如果他/她在给定的时间段内空闲,我想将用户发送到。我已经尝试过 primefaces<p:idlemonitor>
但无法弄清楚如何实现这一点。
user3575427
问问题
814 次
2 回答
1
使用IdleMonitor
组件<p:idleMonitor>
<p:idleMonitor timeout="3000">
<p:ajax event="idle" listener="#{idleMonitorBean.processTimeOut()}"/>
</p:idleMonitor>
注意:timeout
以毫秒为单位
然后在您的侦听器方法中指定redirect()
路径。
@Model
public class IdleMonitorBean {
public void processTimeOut() throws IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect(
"/contextroot/index.xhtml");
}
}
于 2014-05-04T09:40:47.083 回答
0
您可以观察用户活动,例如点击(也许您认为鼠标移动或滚动并不理想,完全取决于您)。
var resetActivityTimer = function () {
if (typeof window.userActivity != 'undefined')
clearTimeout(window.userActivity);
window.userActivity = setTimeout(function () {
window.location.href = 'login.xhtml';
//number of ms until to be considered as ideal
}, 30000);
};
$(window).click(function () {
//if user clicked he/she is not ideal
resetActivityTimer();
});
//initialize timer
resetActivityTimer();
请注意,如果您想将滚动或鼠标移动视为活动,请不要忘记限制事件。
于 2014-05-04T12:00:21.123 回答