在 JSF 和 Richfaces 中处理过期的 ViewState
我有一系列相互构建的注册页面。 当用户会话过期时,我有一个监听器可以清理服务器上的所有内容,并且效果很好。 但是,如果用户尝试执行其他操作,我只想将他们重定向回该系列的第一页。 但是,我的过滤器似乎无法正常工作。 我不断收到 javax.faces.application.ViewExpiredException
处理此异常的最佳实践是什么? 我真的不能只在 web.xml 中处理,因为那太全局化了。 另外,错误页面是从一些 JSF 代码渲染的 - 似乎我需要使用 PhaseListener 来捕获这种情况,这样异常就不会首先发生,但我一直无法找到一个好的模型了解如何执行此操作。 有任何想法吗?
I have a series signup pages that build on each other. When the users session expires I have a Listener that cleans everything up on the server and that works great. But, if the user attempts to do anything else I just want to redirect them back to the first page of the series. However, my filter doesn't seem to work correctly. I keep getting javax.faces.application.ViewExpiredException
What is the best practice for handling this expcetion? I can't really just handle in web.xml because that's too global. Plus the Error page is being rendered from some JSF code - it seems like I need to catch that this is happening using a PhaseListener so the exception doesn't happen in the first place, but I haven't been able to find a good model for how to do this. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Richfaces 有自己的处理 ViewExpiredException 的机制,请参阅 Richfaces文档。
Richfaces has their own mechanism for handling ViewExpiredException, look at Richfaces docs.
我认为你是带有相位监听器的正确曲目。 本质上是在第一页的会话中设置一些东西。 然后在阶段侦听器中查找会话中的值。 如果它不退出,则进行重定向。 诀窍是在阶段侦听器过程的早期进行此操作。
不确定您的阶段侦听器在进程中的具体位置抛出异常。
I think you are the correct track with a phase listener. Essentially set something up in session on the first page. Then in phase listener look for the value in session. If it doesn't exit then do a redirect. The trick is to do it early in the phase listener process.
Not sure exactly where in the process your phase listener is throwing the exception.
我处理这个问题的方法是向 web.xml 添加一个过滤器,仅映射到您想要跟踪的 URL。 该过滤器检查会话是否过期,如果过期则转发到登录页面。 如果过滤器在任何 JSF 代码运行之前运行,它应该可以工作。
The way I handle this is to add a filter to the web.xml only mapped to the urls you want to track. That filter checks if the session is expired, and then forwards to a login page if it is. It should work if the filter is run before any JSF code is run.
我过去处理这个问题的方法是使用一个侦听器来检查托管会话 bean 中的字段。 如果用户会话超时,侦听器会清理 mbean 并将用户标记为未登录。每个请求都通过侦听器发送,如果不满足要求,则用户将被强制退出站点。 我的日志中从未收到 ViewExpiredException 。 发生此异常的唯一情况是服务器已重新启动并且用户在具有先前的活动会话时请求页面。
The way I have handled this in the past is to use a listener which checks a field in a managed session bean. If the users session times out a listener cleans up the mbean and marks the user as not logged in. Every request is sent through the listener and if the requirements are not met then the user is forced out of the site. I never get ViewExpiredException in my log. The only time this exception has occurred is if the server has been restarted and the user requests a page when having a previous active session.
您可以检查您的会话是否无效
如果会话以任何方式无效,这里布尔变量 sessionInValid 将返回 true。
您可以将其添加到过滤器或侦听器中,然后在 web.xml 文件中进行配置。
You can check whether you session is invalidate or not
Here the boolean variable sessionInValid will return true if the session is invalidate by any means.
You can add this in a filter or a listener then configure this in your web.xml file.