如何使seam POJO会话无效

时间:2023-01-16 20:01:37

I am playing around with a little seam app that has session scope. The last method is sending as mail. How can I invalidate my session after having the mail sent? Right now, when the user calls the initial url again, the session still lives and all of the previously filled in form data is still there.

我正在玩一个有会话范围的小缝应用程序。最后一种方法是作为邮件发送。如何在发送邮件后使会话无效?现在,当用户再次调用初始URL时,会话仍然存在,并且所有先前填写的表单数据仍然存在。

I have found examples how to do that with conversations and ejb, but not with POJOs and sessions.

我已经找到了如何使用对话和ejb执行此操作的示例,但没有找到POJO和会话。

Thanks, Rory

2 个解决方案

#1


Per ISASI's answer you can use this code to invalidate the session:

根据ISASI的回答,您可以使用此代码使会话无效:

Session.instance().invalidate();

In answer to your follow up "question" (which you added as an answer, bizarrely). To close the session after informing the user of the sucess then you create a "confirm" page and redirect to it based on a rule associated with the "success" outcome. Then create a page action to invalidate the session.

在回答你的后续“问题”(你作为答案添加,奇怪)。要在通知用户成功后关闭会话,然后创建“确认”页面并根据与“成功”结果相关联的规则重定向到该页面。然后创建页面操作以使会话无效。

<page view-id="/process/confirm.xhtml" action="#{emailManager.completeSession}">

Technically, the session will be closed beofre rendering the page, so that may create a timing issue with regards accessing session data, so you may need to hack around with page parameters to compensate. This is because you are basically doing it "wrong" by using a session per email. You'll be much better off using a conversation because there is an @End annotation that ends the conversation after rendering the view - much easier.

从技术上讲,会话将关闭呈现页面,因此可能会产生关于访问会话数据的计时问题,因此您可能需要使用页面参数进行修复以进行补偿。这是因为你基本上是通过每个电子邮件使用一个会话来“错误”。使用对话会更好,因为有一个@End注释在渲染视图后结束对话 - 更容易。

You'll need to switch to using conversations once your application involves more than one task as any state held between tasks will be lost. I imagine that will happen quite quickly. These timing and state management issues are the problem Seam conversations was designed to solve.

一旦您的应用程序涉及多个任务,您将需要切换到使用对话,因为任务之间的任何状态都将丢失。我想这会很快发生。这些时间和状态管理问题是Seam对话旨在解决的问题。

#2


Session.instance().invalidate();

#1


Per ISASI's answer you can use this code to invalidate the session:

根据ISASI的回答,您可以使用此代码使会话无效:

Session.instance().invalidate();

In answer to your follow up "question" (which you added as an answer, bizarrely). To close the session after informing the user of the sucess then you create a "confirm" page and redirect to it based on a rule associated with the "success" outcome. Then create a page action to invalidate the session.

在回答你的后续“问题”(你作为答案添加,奇怪)。要在通知用户成功后关闭会话,然后创建“确认”页面并根据与“成功”结果相关联的规则重定向到该页面。然后创建页面操作以使会话无效。

<page view-id="/process/confirm.xhtml" action="#{emailManager.completeSession}">

Technically, the session will be closed beofre rendering the page, so that may create a timing issue with regards accessing session data, so you may need to hack around with page parameters to compensate. This is because you are basically doing it "wrong" by using a session per email. You'll be much better off using a conversation because there is an @End annotation that ends the conversation after rendering the view - much easier.

从技术上讲,会话将关闭呈现页面,因此可能会产生关于访问会话数据的计时问题,因此您可能需要使用页面参数进行修复以进行补偿。这是因为你基本上是通过每个电子邮件使用一个会话来“错误”。使用对话会更好,因为有一个@End注释在渲染视图后结束对话 - 更容易。

You'll need to switch to using conversations once your application involves more than one task as any state held between tasks will be lost. I imagine that will happen quite quickly. These timing and state management issues are the problem Seam conversations was designed to solve.

一旦您的应用程序涉及多个任务,您将需要切换到使用对话,因为任务之间的任何状态都将丢失。我想这会很快发生。这些时间和状态管理问题是Seam对话旨在解决的问题。

#2


Session.instance().invalidate();