SCALA Lift - Comet Actor 内的 S.param 访问
我正在尝试检索 CometActor 中的 url 参数,以验证数据源是否与目的地匹配,例如,用户从房间 A 发送一条消息,该消息应该仅在房间 A 中接收和显示,而不是在房间 B 或 C 中。
我试过了:
S.param("message").openOr("")
但是总是空的,这样可以吗?或者有其他方法可以阻止彗星消息到达不该到达的地方吗?
预先感谢您的任何帮助,非常感谢:)
I'm attempting to retrieve a url parameter within a CometActor to validate that the source of the data matches the destination, e.g A user sends a message from room A, which should be received and displayed only in room A, not B or C.
I've tried:
S.param("message").openOr("")
But it's always empty, can this be done? Or is there another way to stop Comet messages going where they shouldn't?
Thanks in advance for any help, much appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CometActor 存在于会话之外,因此无法访问(大部分)会话。解决方案是使用包含所需会话数据的初始化消息来初始化参与者。有某种帮助程序(也许在 LiftRules 中)可以做到这一点。我正在手机上凭记忆复述这一切,但希望这足以继续下去。
具体来说,您需要
在
Boot.scala
中执行以下操作:查看
LiftSession
再多一点。我认为可能有一种方法可以连接到LiftRules
在会话创建时调用相关代码...更新:如果我们发送一个包含以下内容的案例类,您的 CometActor 可能会是什么样子:
CometActors exist outside of the session and so don't have access to (most of) it. The solution is to initialize the actor with an initialization message containing the desired session data. There's some sort of helper, perhaps in LiftRules, to do that. I'm on my phone and recounting this from memory but hopefully it's enough to go on.
Specifically, you're going to want to do something like:
in your
Boot.scala
.Check out
LiftSession
for a little more. I think there might be a way to hook intoLiftRules
to have the relevant code called upon session creation...Update: And here's what your CometActor might look like if we send a case class containing:
来自 Lift 的邮件列表:
这是一种可能的选择。但是,我个人的偏好是使用
NamedCometActorSnippet
将彗星插入页面,并立即向创建的彗星发送消息:From Lift's mailing list:
This is one possible option. However, my personal preference is to insert comets to page using
NamedCometActorSnippet
and send a message to created comet immediately: