SCALA提升 - 在彗星演员S.param访问 [英] SCALA Lift - S.param access within Comet Actor

查看:116
本文介绍了SCALA提升 - 在彗星演员S.param访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图一个CometActor内检索URL参数,以验证数据源的目标,例如,一个用户发送从一个房间一个消息匹配,它应该接收,只在房间A,否B显示或C。

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.

我已经试过:

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?

在此先感谢您的帮助,很多AP preciated:)

Thanks in advance for any help, much appreciated :)

推荐答案

CometActors会话之外存在,所以不必访问(大部分)它。解决的办法是初始化演员用含有所需的会话数据的初始化消息。有某种形式的帮助,也许在LiftRules,做到这一点。我对我的手机,并从内存中讲述这一点,但希望它足够去。

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:

for (
  session <- S.session
  message <- S.param("message")
) {
  session.setupComet("myCometActor", Some("unique name, if you want it"), message)
}

Boot.scala

查看 LiftSession 多一点。我觉得可能是一种方式挂接到 LiftRules 具备相关的code呼吁会话创建...

Check out LiftSession for a little more. I think there might be a way to hook into LiftRules to have the relevant code called upon session creation...

更新:这是你的CometActor可能是什么样子,如果我们发送包含案例类:

Update: And here's what your CometActor might look like if we send a case class containing:

// ...
session.setupComet(
  "myCometActor",
  Some("unique name, if you want it"),
  Message(message)
)
// ...
case class Message(text: String)

class CometMessage extends CometActor { 
  override def lowPriority = {
    case Message(text) => {
      // do something here with the text, whether settings a SessionVar or even just a plain var
    }
  }
}

这篇关于SCALA提升 - 在彗星演员S.param访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆