我想通过idlemonitor,primefaces组件处理会话超时。通过idlemonitor(primefaces)超时
我这样做是因为我需要让用户知道由于闲置会话已过期。我需要通过对话框显示此消息,关闭对话框后,他应该重定向到登录页面。他不应该能够点击“返回”并浏览应用程序,就像什么都没有发生;如果他点击“返回”,他应该被重定向到sessionexpired.xhtml页面。
我把idleMonitor我loggedintemplate.xhtml,所以它只能如果您已经登录,在什么页面,东阳我的所有网页,您登录后,从显示LoggedInTemplate派生不管。 xhtml。
这是我loggedintemplate.xhtml代码的样子:
<p:idleMonitor timeout="6000" onidle="idleDialog.show()" />
<p:dialog header="Timeout" resizable="false" closable="false"
widgetVar="idleDialog" modal="true">
<p:panel styleClass="noborderpanel">
<p:panelGrid columns="1" styleClass="adressegrid">
<p:outputLabel value="Session has expired due to inactivity" />
<p:commandButton action="#{loginController.timeout()}"
value="Ok" />
</p:panelGrid>
</p:panel>
</p:dialog>
所以这个代码的功能基本上检查,如果用户不活跃,持续6秒,如果他是无效的,弹出一个不可关闭的对话框并告诉他该会话已过期。
的方法loginController.timeout()应注销用户,无效的会话等
我的问题是,我不知道如何会话无效,如何注销用户等如果我使用FacesContext.getCurrentInstance().getExternalContext() .invalidateSession();
它会使会话无效,但我需要更多。例如,如果用户处于非活动状态超过30分钟,默认的JavaEE超时时间,我会得到一个nullPointerException。
我想处理超时“手动”,有没有办法来禁用默认的JavaEE超时?
什么是手动处理超时的最佳方式,而不是像这样:
<session-config>
<session-timeout>20</session-timeout>
</session-config>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/expired.xhtml</location>
</error-page>
我想如果你那句你的问题更具体你可以提高你的答案的机会。我不知道是否可以在web.xml中全部禁用会话超时。您可以将其设置为8小时,然后以您已经这样做的方式自行使会话失效。那么NPE只需检查一下。我们完全按照这种方式使用它(使用primefaces idlemonitor)。 – Jens 2013-03-20 22:16:09
我不明白你的意思是“检查这个”? – leostiw 2013-03-21 07:34:55
您何时何地获得NPE?这些'FacesContext.getCurrentInstance()。getExternalContext()。invalidateSession();'是'null'和什么时间? (检查这是否意味着:包括像if(objectThatCouldBeNull!= null)这样的检查 – Jens 2013-03-21 07:57:35