如何检查 JSF 页面中是否存在活动会话?
有没有办法直接在jsf页面中检查是否有活动会话? 我已经尝试过,但不起作用:
<p:ajaxStatus onerror="#{session == null ? 'idleDialog.show();' : null}"
提前谢谢您
@Update 我发现即使发生 viewExpiredException,onerror 也不会被触发。
there is a way to check if there is an active session directly in jsf page?
I have try this but it doesn't work:
<p:ajaxStatus onerror="#{session == null ? 'idleDialog.show();' : null}"
thank you in advance
@Update
I have see that onerror isn't fired even if viewExpiredException occurr.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
评估 EL 时始终存在活动会话。如果页面打开之前不存在,则会自动创建。
在 JSF 中,由于所谓的“状态保存方法”,过期会话是一个问题。默认情况下,生成的页面的状态存储在会话中。如果您尝试提交表单并且会话已过期,则状态会丢失并因此发生错误。
但即使在这种情况下,也会生成一个新会话。因此,正如 BalusC 所指出的,您可以保持会话处于活动状态 - 使用 ajax 请求进行轮询(例如 richfaces 具有此类功能),以便会话永远不会过期
There is always an active session at the time the EL is evaluated. If there isn't before the page was opened, it is automatically created.
In JSF expiring sessions are a problem because of the so called "state saving method". By default the state of the generated page is stored in the session. If you try to submit the form and the session is expired, the state is lost and hence an error occurs.
But even in that case a new session is generated. So, as BalusC noted, you can keep the session alive - poll with ajax requests (for example richfaces has such facilities) so that the session never expires
您可以在 JSF 2.0 中使用以下 EL 表达式:
#{facesContext.externalContext.getSession(false) == null}
请注意,引用隐式 EL 对象
session
将自动再次(重新)创建它。因此,这个永远不能用于测试。例如,
假设您在支持 bean 中使会话无效,并且呈现了具有以下内容的 Facelet:
这将呈现:
会话首先真正消失,但通过引用隐式 EL 对象,它再次创建(并且将在新状态)。然后第二个测试发现会话再次存在。
You can use the following EL expression in JSF 2.0:
#{facesContext.externalContext.getSession(false) == null}
Do note that referencing the implicit EL object
session
will automatically (re)create it again. This one can thus never be used for testing.E.g.
Suppose you would have invalidated the session in a backing bean, and a Facelet with the following content was rendered:
This would render:
The session is first really gone, but by referencing the implicit EL object it's created again (and will be in the new state). The second test then finds the session to be there again.